當前位置: 首頁>>代碼示例>>Python>>正文


Python restful.Api方法代碼示例

本文整理匯總了Python中flask.ext.restful.Api方法的典型用法代碼示例。如果您正苦於以下問題:Python restful.Api方法的具體用法?Python restful.Api怎麽用?Python restful.Api使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask.ext.restful的用法示例。


在下文中一共展示了restful.Api方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from flask.ext import restful [as 別名]
# 或者: from flask.ext.restful import Api [as 別名]
def __init__(self):
        self.app = Flask(__name__)
        custom_errors = {
            'JsonInvalidError': {
                'status': 500,
                'message': 'JSON format not valid'
            },
            'JsonRequiredError': {
                'status': 400,
                'message': 'JSON input required'
            }
        }
        self.api = swagger.docs(Api(self.app, errors=custom_errors), apiVersion=API_VERSION_NUMBER)
        
        self.api.add_resource(DummyEndpoint, '/dummy', endpoint='dummy')
        self.api.add_resource(HelloEndpoint, '/hello', endpoint='hello') 
開發者ID:bonzanini,項目名稱:flask-api-template,代碼行數:18,代碼來源:server.py

示例2: create_api

# 需要導入模塊: from flask.ext import restful [as 別名]
# 或者: from flask.ext.restful import Api [as 別名]
def create_api(app):
    from flask.ext.restful import Api
    from api import add_resources

    api = Api(catch_all_404s=True)
    api = add_resources(api)
    api.init_app(app)

    return api 
開發者ID:MacroConnections,項目名稱:DIVE-backend,代碼行數:11,代碼來源:core.py

示例3: lmio_api

# 需要導入模塊: from flask.ext import restful [as 別名]
# 或者: from flask.ext.restful import Api [as 別名]
def lmio_api(dev=False, username=None, password=None):
    r"""
    Generate a Flask App that will serve meshes landmarks and templates to
    landmarker.io

    Parameters
    ----------
    adapter: :class:`LandmarkerIOAdapter`
        Concrete implementation of the LandmarkerIOAdapter. Will be queried for
        all data to pass to landmarker.io.
    dev: `bool`, optional
        If True, listen to anyone for CORS.
    username : str, optional
        If provided basic auth will be applied for this username. Requires
        password to also be provided.
    password : str, optional
        If provided basic auth will be applied for this password. Requires
        username to also be provided.

    Returns
    -------
    api, app, api_endpoint
    """
    app = Flask(__name__)  # create the flask app

    # 1. configure CORS decorator

    cors_dict = {
        'allowed_origins': Server.allowed_origins,
        'headers': ['Origin', 'X-Requested-With', 'Content-Type', 'Accept'],
        'methods': ['HEAD', 'GET', 'POST', 'PATCH', 'PUT', 'OPTIONS', 'DELETE'],
        'credentials': True
    }

    if dev:
        # in development mode we can't use basic auth
        cors_dict['credentials'] = False
        app.debug = True

    # create the cors decorator
    decorators = [cors.crossdomain(**cors_dict)]

    if username is not None and password is not None:
        print('enabling basic auth')
        # note the we cors is the last decorator -> the first that is hit. This
        # is what we want as CORS will detect OPTIONS requests and allow them
        # immediately. All other requests will be sent through the basicauth
        # decorator.
        decorators.insert(0, basicauth(username, password))

    api = Api(app, decorators=decorators)

    return api, app 
開發者ID:menpo,項目名稱:landmarkerio-server,代碼行數:55,代碼來源:server.py


注:本文中的flask.ext.restful.Api方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。