Last active
June 28, 2023 18:24
Revisions
-
wshayes revised this gist
Apr 13, 2020 . 1 changed file with 21 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ # From: https://github.com/tiangolo/fastapi/issues/23#issuecomment-597631374 # The following works with the pycharm debugger with reload running in a docker-compose remote interpreter from fastapi import FastAPI import uvicorn app = FastAPI() @app.get("/") def root(): a = "a" b = "b" + a return {"hello world": b} if __name__ == '__main__': uvicorn.run("main:app", host='0.0.0.0', port=8000, reload=True) # Notice the it's "main:app" and not app otherwise you get an error: # WARNING: You must pass the application as an import string to enable 'reload' or 'workers'. -
wshayes revised this gist
Mar 26, 2020 . 1 changed file with 22 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,32 @@ #!/usr/bin/env python3.7 import logging import uvicorn from fastapi import FastAPI from starlette.responses import RedirectResponse from starlette.testclient import TestClient log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) app = FastAPI() @app.get("/") def read_main(): return {"message": "Hello World from main app"} @app.get("/test/{check:path}") def test_slash(check: str): """Test if forward slash can be captured https://fastapi.tiangolo.com/tutorial/path-params/#path-convertor """ return {"message": check} subapi = FastAPI(openapi_prefix="/subapi") @@ -32,7 +44,7 @@ async def redirect(): @subapi.get("/redirected") async def redirected(): log.debug("REDIRECTED") return {"message": "you've been redirected"} @@ -45,4 +57,8 @@ async def redirected(): def test_redirect_subapi(): url = app.url_path_for("redirect") response = client.get(url) assert response.json() == {"message": "you've been redirected"} if __name__ == "__main__": uvicorn.run("fastapi_test:app", host="127.0.0.1", port=5000, log_level="info") -
wshayes revised this gist
May 15, 2019 . No changes.There are no files selected for viewing
-
wshayes created this gist
May 15, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ import logging from fastapi import FastAPI from starlette.responses import RedirectResponse from starlette.testclient import TestClient logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) app = FastAPI() @app.get("/app") def read_main(): return {"message": "Hello World from main app"} subapi = FastAPI(openapi_prefix="/subapi") @subapi.get("/sub") async def read_sub(): return {"message": "Hello World from sub API"} @subapi.get("/redirect") async def redirect(): url = app.url_path_for("redirected") response = RedirectResponse(url=url) return response @subapi.get("/redirected") async def redirected(): logger.debug("REDIRECTED") return {"message": "you've been redirected"} app.mount("/subapi", subapi) client = TestClient(app) def test_redirect_subapi(): url = app.url_path_for("redirect") response = client.get(url) assert response.json() == {"message": "you've been redirected"}