Пример #1
0
def create_api(app):
    global db_con
    db_con = app.config['db']

    my_api = Api(app)

    from iamalive.api.api import Device, DeviceToken, DeviceDetails, DeviceList, AuthenticateUser, Pong, DeviceStatus, custom_errors
    my_api.add_resource(Pong, '/api/v1/ping')
    my_api.add_resource(Device, '/api/v1/device/<string:device_id>')
    my_api.add_resource(DeviceList, '/api/v1/device')
    my_api.add_resource(DeviceToken, '/api/v1/device/<string:device_id>/token')
    my_api.add_resource(DeviceDetails, '/api/v1/device/<string:device_id>/details')
    my_api.add_resource(DeviceStatus, '/api/v1/device/<string:device_id>/status')
    my_api.add_resource(AuthenticateUser, '/api/v1/authenticate')
    my_api.errors = custom_errors
Пример #2
0
from .settings import HOST, PORT, PROJECT


# Entire Flask application and its configuration.
app = Flask(__name__)
app.config.from_object(config.config[settings.CONFIG])

# Exposing API capabilities and (de)serialization schemas.
api_bp = Blueprint("api", __name__)
api = Api(api_bp)
ma = Marshmallow(app)

# Websockets.
sio = SocketIO(app)


from . import views


api.errors = views.api.ERRORS
app.register_blueprint(api_bp, url_prefix=views.api.URL_PREFIX)


def run_server(conf=settings.CONFIG):
    app.config.from_object(config.config[conf])
    sio.run(
        app,
        host=HOST,
        port=PORT,
    )
Пример #3
0
    format="%(levelname)s - %(name)s - %(asctime)s - %(message)s",
    level=level
)
config.init_url_opening()
config.init_datastore_emulator()

app = Flask(__name__)
app.config.from_object(config.config[settings.CONFIG])
app.jinja_env.add_extension("jinja2.ext.loopcontrols")
CORS(app)
ndb_wsgi_middleware(app)

json = FlaskJSON(app)

# NOTE(cmiN): Remember that the original `get_remote_address` always returns
#  "127.0.0.1" under GAE deployment.
limiter = Limiter(app, key_func=get_remote_address)

api_bp = Blueprint("api", __name__)
api = Api(api_bp)
app.register_blueprint(api_bp, url_prefix="/api")

ma = Marshmallow(app)


# Due to circular imports and for routing to take effect.
from . import resources, views


api.errors = resources.ERRORS