def init(): from app.api import API from app.utils.database import db_session, init_session from app.middleware import AuthHandler, JSONTranslator, DatabaseSessionManager init_session() middleware = [ AuthHandler(), JSONTranslator(), DatabaseSessionManager(db_session) ] application = API(middleware=middleware) LOG.info('API Server is starting') return application
import falcon from app.api.v1 import users from app.middleware import DatabaseSessionManager from app.database import db_session, init_session from app.api.common import base class App(falcon.API): def __init__(self, *args, **kwargs): super(App, self).__init__(*args, **kwargs) self.add_route('/', base.BaseResource()) self.add_route('/v1/users', users.Collection()) init_session() mdlw = [DatabaseSessionManager(db_session)] application = App(middleware=mdlw)
self.add_route("/app/api/apiv1/create_user", userauth.Collection()) self.add_route("/app/api/apiv1/create_group", userauth.Collection()) self.add_route("/app/api/apiv1/update_records", userauth.Collection()) self.add_route("/app/api/apiv1/delete_records", userauth.Collection()) self.add_route("/app/api/apiv1/capture_video", videocapture.VideoCapture()) self.add_route("/app/api/apiv1/stop_video", videocapture.VideoCapture()) self.add_route("/app/api/apiv1/status", videocapture.VideoCapture()) self.add_error_handler(AppError, AppError.handle) init_session() middleware = [ JSONTranslator(), DatabaseSessionManager(db_session), ResponseLogger(), RedixDb(), CorsMiddleware() ] application = App(middleware=middleware) '''def application(env, start_response): uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', '')) uwsgi.websocket_send("Hello world") while True: msg = uwsgi.websocket_recv() uwsgi.websocket_send(msg)''' if __name__ == "__main__": from wsgiref import simple_server
def client(): config.DB_AUTOCOMMIT = False init_session() middleware = [JSONTranslator(), DatabaseSessionManager(db_session)] return testing.TestClient(App(middleware=middleware))
LOG = log.get_logger() class App(falcon.API): def __init__(self, *args, **kwargs): super(App, self).__init__(*args, **kwargs) LOG.info("API Server is starting") self.add_route("/", base.BaseResource()) self.add_route("/v1/users", users.Collection()) self.add_route("/v1/users/{user_id}", users.Item()) self.add_route("/v1/users/self/login", users.Self()) self.add_route("/v1/users/info/self", users.UserInformation()) self.add_route("/v1/users/info", users.AllUserInformation()) self.add_route("/v1/deploy", deployment.Deployment()) self.add_error_handler(AppError, AppError.handle) init_session() middleware = [AuthHandler(), JSONTranslator(), DatabaseSessionManager(db_session), HandleCORS()] application = App(middleware=middleware) if __name__ == "__main__": from wsgiref import simple_server httpd = simple_server.make_server("127.0.0.1", 5000, application) httpd.serve_forever()
self.add_route('/v2/NotificationCount', v2_notification.NotificationCount()) self.add_route('/v3/Notifications', v2_notification.Notifications()) # User Information self.add_route('/v2/User/PaymentAccount', v2_user.PaymentAccount()) self.add_route('/v2/User/PersonalInfo', v2_user.PersonalInfo()) # Statistics self.add_route('/v2/Statistics/Token/{contract_address}', v2_statistics.Token()) """ Version 3 """ # Notifications self.add_route('/v3/Notifications', v3_notification.Notifications()) self.add_route('/v3/Notifications/{id}', v3_notification.NotificationsId()) """ Error Handler """ self.add_error_handler(AppError, AppError.handle) init_session() middleware = [JSONTranslator(), DatabaseSessionManager(db_session), CORSMiddleware()] application = App(middleware=middleware) LOG.info("Service started successfully")