Python flask.ext.restful.Api() Examples
The following are 3
code examples of flask.ext.restful.Api().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.ext.restful
, or try the search function
.
Example #1
Source File: server.py From flask-api-template with MIT License | 6 votes |
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')
Example #2
Source File: core.py From DIVE-backend with GNU General Public License v3.0 | 5 votes |
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
Example #3
Source File: server.py From landmarkerio-server with BSD 3-Clause "New" or "Revised" License | 4 votes |
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