From 167befc8ed6fd8e327b4554f6716bbc1d7f3531b Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Sat, 5 Jun 2021 18:46:08 +0530 Subject: added FastAPI support --- api.py | 11 +++++++++++ app/apis.py | 9 +++++++++ app/tests/test_fastapi.py | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 api.py create mode 100644 app/apis.py create mode 100644 app/tests/test_fastapi.py diff --git a/api.py b/api.py new file mode 100644 index 0000000..35f902c --- /dev/null +++ b/api.py @@ -0,0 +1,11 @@ +from app import app as flask_app +from fastapi import Body, FastAPI +from fastapi.middleware.wsgi import WSGIMiddleware +from pydantic import BaseModel + + +app = FastAPI(title="SaaS-in-a-Flask",description="Sample API", version="0.1") + +from app import apis + +app.mount("/", WSGIMiddleware(flask_app)) diff --git a/app/apis.py b/app/apis.py new file mode 100644 index 0000000..df6ddd1 --- /dev/null +++ b/app/apis.py @@ -0,0 +1,9 @@ +from api import app + +from fastapi import Body, FastAPI +from fastapi.middleware.wsgi import WSGIMiddleware +from pydantic import BaseModel + +@app.get("/version") +async def API_Version(): + return {"message":app.version} \ No newline at end of file diff --git a/app/tests/test_fastapi.py b/app/tests/test_fastapi.py new file mode 100644 index 0000000..c6b40cc --- /dev/null +++ b/app/tests/test_fastapi.py @@ -0,0 +1,10 @@ +from starlette.testclient import TestClient + +from api import app as fastapi_app + +fastapi_client = TestClient(fastapi_app) + +def test_fastapi(app, client): + res = fastapi_client.get("/version") + assert res.status_code == 200 + assert res.json() == {"message":fastapi_app.version} \ No newline at end of file -- cgit v1.2.3