Skip to content
Snippets Groups Projects

Switched to asynchronous quart framework

Merged Felix Delattre requested to merge feature/switched-to-async into master
6 files
+ 57
45
Compare changes
  • Side-by-side
  • Inline

Files

+ 14
33
@@ -19,45 +19,26 @@
import logging
import sys
from flask import Flask, request, Response
from jsonrpcserver import method, dispatch
from quart import Quart
from .jsonrpcquart import JSONRPCQuart
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.info("obmapidata has started")
def create_app(test_config=None):
"""Create and configure an instance of the Flask application."""
logger.info("obmapidata has started")
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
# a default secret that should be overridden by instance config
SECRET_KEY="dev"
)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile("config.py", silent=True)
else:
# load the test config if passed in
app.config.update(test_config)
@method
def ping():
return "pong"
@app.route("/", methods=["POST"])
def index():
req = request.get_data().decode()
response = dispatch(req)
return Response(str(response), response.http_status, mimetype="application/json")
app = Quart(__name__)
app.api = JSONRPCQuart()
return app
app.route(
"/",
methods=[
"POST",
],
)(app.api.handler)
if __name__ == "__main__":
create_app().run()
@app.api.add_function
async def ping():
return "pong"
Loading