当前位置: 首页>>代码示例>>Python>>正文


Python flask_restplus.Api方法代码示例

本文整理汇总了Python中flask_restplus.Api方法的典型用法代码示例。如果您正苦于以下问题:Python flask_restplus.Api方法的具体用法?Python flask_restplus.Api怎么用?Python flask_restplus.Api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_restplus的用法示例。


在下文中一共展示了flask_restplus.Api方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initialize_api

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def initialize_api(self):
        """Initialize an API."""
        blueprint = flask.Blueprint("api", __name__, url_prefix="/api")

        api = flask_restplus.Api(version="1.0", title="BigGraphite API")
        api.namespaces = []
        api.add_namespace(ns_bgutil.api)
        api.add_namespace(ns_biggraphite.api)
        api.init_app(blueprint)

        self.app.register_blueprint(blueprint)

        if flask_cors:
            # Allow others to request swagger stuff without restrictions.
            # This helps for https reverse proxy with bad headers.
            flask_cors.CORS(
                self.app, resources={r"/api/swagger.json": {"origins": "*"}}) 
开发者ID:criteo,项目名称:biggraphite,代码行数:19,代码来源:app.py

示例2: setUp

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def setUp(self):
        """Initialize the app with the corresponding logic."""
        self.app = flask.Flask(__name__)
        self.app.testing = True
        self.app.json_encoder = rest.CompliantJsonEncoder

        api = restplus.Api(self.app)
        error_handlers.register(api)

        cors = webutils.cors(origin='*',
                             content_type='application/json',
                             credentials=False)
        self.impl = mock.Mock()

        scheduler.init(api, cors, self.impl)
        self.client = self.app.test_client() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:18,代码来源:scheduler_test.py

示例3: create_app

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def create_app():
    from thoughts_backend.api_namespace import api_namespace
    from thoughts_backend.admin_namespace import admin_namespace

    application = Flask(__name__)
    api = Api(application, version='0.1', title='Thoughts Backend API',
              description='A Simple CRUD API')

    from thoughts_backend.db import db, db_config
    application.config['RESTPLUS_MASK_SWAGGER'] = False
    application.config.update(db_config)
    db.init_app(application)
    application.db = db

    api.add_namespace(api_namespace)
    api.add_namespace(admin_namespace)

    return application 
开发者ID:PacktPublishing,项目名称:Hands-On-Docker-for-Microservices-with-Python,代码行数:20,代码来源:app.py

示例4: create_app

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def create_app():
    from users_backend.api_namespace import api_namespace
    from users_backend.admin_namespace import admin_namespace

    application = Flask(__name__)
    api = Api(application, version='0.1', title='Users Backend API',
              description='A Simple CRUD API')

    from users_backend.db import db, db_config
    application.config['RESTPLUS_MASK_SWAGGER'] = False
    application.config.update(db_config)
    db.init_app(application)
    application.db = db

    api.add_namespace(api_namespace)
    api.add_namespace(admin_namespace)

    return application 
开发者ID:PacktPublishing,项目名称:Hands-On-Docker-for-Microservices-with-Python,代码行数:20,代码来源:app.py

示例5: create_app

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def create_app(script=False):
    from users_backend.api_namespace import api_namespace
    from users_backend.admin_namespace import admin_namespace

    application = Flask(__name__)

    if not script:
        # Initialise metrics
        metrics.init_app(application)

    api = Api(application, version='0.1', title='Users Backend API',
              description='A Simple CRUD API')

    from users_backend.db import db, db_config
    application.config['RESTPLUS_MASK_SWAGGER'] = False
    application.config.update(db_config)
    db.init_app(application)
    application.db = db

    api.add_namespace(api_namespace)
    api.add_namespace(admin_namespace)

    return application 
开发者ID:PacktPublishing,项目名称:Hands-On-Docker-for-Microservices-with-Python,代码行数:25,代码来源:app.py

示例6: create_app

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def create_app(script=False):
    from users_backend.api_namespace import api_namespace
    from users_backend.admin_namespace import admin_namespace

    application = Flask(__name__)

    if not script:
        # Initialise metrics
        metrics.init_app(application)

    api = Api(application, version=VERSION, title='Users Backend API',
              description='A Simple CRUD API')

    from users_backend.db import db, db_config
    application.config['RESTPLUS_MASK_SWAGGER'] = False
    application.config.update(db_config)
    db.init_app(application)
    application.db = db

    api.add_namespace(api_namespace)
    api.add_namespace(admin_namespace)

    return application 
开发者ID:PacktPublishing,项目名称:Hands-On-Docker-for-Microservices-with-Python,代码行数:25,代码来源:app.py

示例7: flaskshop_load_blueprints

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def flaskshop_load_blueprints(app):
    bp = Blueprint("api", __name__)

    csrf_protect.exempt(bp)
    bp.session_interface = CustomSessionInterface()
    ALLOWED_PATHS = frozenset(
        ["/api/v1/user/login", "/api/v1/", "/api/v1/swagger.json", "/api/v1/products/"]
    )

    @bp.after_request
    def verify_user(response):
        from .auth import verify_token

        if request.path in ALLOWED_PATHS or request.method == "OPTIONS":
            return response
        elif "Authorization" in request.headers:
            data = verify_token(request.headers["Authorization"])
            if data:
                return response
        return "", 401

    api = Api(bp, version="1.0", title="Saleor API", description="A simple API")

    @api.errorhandler
    def default_error_handler(error):
        """Default error handler"""
        return {"message": str(error)}, getattr(error, "code", 500)

    api.add_namespace(product_api)
    api.add_namespace(checkout_api)
    api.add_namespace(auth_api)

    app.register_blueprint(bp, url_prefix="/api/v1") 
开发者ID:hjlarry,项目名称:flask-shop,代码行数:35,代码来源:api.py

示例8: setUp

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def setUp(self):
        """Initialize the app with the corresponding limit logic."""
        blueprint = flask.Blueprint('v1', __name__)
        self.api = restplus.Api(blueprint)

        self.app = flask.Flask(__name__)
        self.app.testing = True
        self.app.register_blueprint(blueprint)

        na = self.api.namespace(
            'na', description='Request Rate Control REST API Test',
        )

        @na.route('/foo')
        class _Foo(restplus.Resource):
            """Request rate control resource example"""

            def get(self):
                """Get resource implement"""
                return ''

        @na.route('/bar')
        class _Bar(restplus.Resource):
            """Request rate control resource example"""

            def get(self):
                """Get resource implement"""
                return ''

        nb = self.api.namespace(
            'nb', description='Request Rate Control REST API Test',
        )

        @nb.route('/baz')
        class _Baz(restplus.Resource):
            """Request rate control resource example"""

            def get(self):
                """Get resource implement"""
                return '' 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:42,代码来源:limit_test.py

示例9: setUp

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def setUp(self):
        """Initialize the app with the corresponding logic."""
        self.app = flask.Flask(__name__)
        self.app.testing = True

        api = restplus.Api(self.app)
        error_handlers.register(api)

        cors = webutils.cors(origin='*',
                             content_type='application/json',
                             credentials=False)
        self.impl = mock.Mock()

        state.init(api, cors, self.impl)
        self.client = self.app.test_client() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:17,代码来源:state_test.py

示例10: setUp

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def setUp(self):
        """Initialize the app with the corresponding logic."""
        self.app = flask.Flask(__name__)
        self.app.testing = True

        api = restplus.Api(self.app)
        error_handlers.register(api)

        cors = webutils.cors(origin='*',
                             content_type='application/json',
                             credentials=False)
        self.impl = mock.Mock()

        instance.init(api, cors, self.impl)
        self.client = self.app.test_client() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:17,代码来源:instance_test.py

示例11: setUp

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def setUp(self):
        """Initialize the app with the corresponding logic."""
        self.app = flask.Flask(__name__)
        self.app.testing = True
        self.impl = mock.Mock()

        api = restplus.Api(self.app)
        cors = webutils.cors(
            origin='*',
            content_type='application/json',
            credentials=False,
        )
        group.init(api, cors, self.impl)

        self.client = self.app.test_client() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:17,代码来源:group_test.py

示例12: setUp

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def setUp(self):
        """Initialize the app with the corresponding logic."""
        self.app = flask.Flask(__name__)
        self.app.testing = True
        self.impl = mock.Mock()

        api = restplus.Api(self.app)
        cors = webutils.cors(origin='*',
                             content_type='application/json',
                             credentials=False)

        error_handlers.register(api)

        local.init(api, cors, self.impl)
        self.client = self.app.test_client() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:17,代码来源:local_test.py

示例13: setUp

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def setUp(self):
        """Initialize the app with the corresponding logic."""
        self.app = flask.Flask(__name__)
        self.app.testing = True

        api = restplus.Api(self.app)
        cors = webutils.cors(origin='*',
                             content_type='application/json',
                             credentials=False)
        self.impl = mock.Mock()

        server.init(api, cors, self.impl)
        self.client = self.app.test_client() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:15,代码来源:server_test.py

示例14: setUp

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def setUp(self):
        """Initialize the app with the corresponding logic."""
        self.app = flask.Flask(__name__)
        self.app.testing = True

        api = restplus.Api(self.app)
        error_handlers.register(api)

        cors = webutils.cors(origin='*',
                             content_type='application/json',
                             credentials=False)
        self.impl = mock.Mock()

        cgroup.init(api, cors, self.impl)
        self.client = self.app.test_client() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:17,代码来源:cgroup_test.py

示例15: create_app

# 需要导入模块: import flask_restplus [as 别名]
# 或者: from flask_restplus import Api [as 别名]
def create_app(script=False):
    from thoughts_backend.api_namespace import api_namespace
    from thoughts_backend.admin_namespace import admin_namespace

    application = Flask(__name__)
    application.before_request(logging_before)
    application.after_request(logging_after)

    # Enable RequestId
    application.config['REQUEST_ID_UNIQUE_VALUE_PREFIX'] = ''
    RequestID(application)

    if not script:
        # For scripts, it should not connect to Syslog
        handler = logging.handlers.SysLogHandler(('syslog', 5140))
        req_format = ('[%(asctime)s] %(levelname)s [%(request_id)s] '
                      '%(module)s: %(message)s')
        handler.setFormatter(RequestFormatter(req_format))
        handler.setLevel(logging.INFO)
        application.logger.addHandler(handler)
        # Do not propagate to avoid log duplication
        application.logger.propagate = False

        # Initialise metrics
        metrics.init_app(application)

    api = Api(application, version='0.1', title='Thoughts Backend API',
              description='A Simple CRUD API')

    from thoughts_backend.db import db, db_config
    application.config['RESTPLUS_MASK_SWAGGER'] = False
    application.config.update(db_config)
    db.init_app(application)
    application.db = db

    api.add_namespace(api_namespace)
    api.add_namespace(admin_namespace)

    return application 
开发者ID:PacktPublishing,项目名称:Hands-On-Docker-for-Microservices-with-Python,代码行数:41,代码来源:app.py


注:本文中的flask_restplus.Api方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。