Created
March 10, 2023 15:21
Revisions
-
danielballan created this gist
Mar 10, 2023 .There are no files selected for viewing
This file contains 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,8 @@ ## Tasks 1. Run `python middlware.py`. 2. Using HTTPie, request data: `http :8000/data`. This should return the list of numbers from the server. 3. Add a simple [middleware](https://fastapi.tiangolo.com/tutorial/middleware/) that just uses `print` to print a message in the server logs before and after a request is seen. 4. Add a second middleware that also prints. Question: Do the middlewares get run in the order that they are added in `middlware.py` or in the _reverse_ order? This file contains 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,14 @@ from fastapi import FastAPI, Request app = FastAPI() @app.get("/data") def data(): return [1, 2, 3] if __name__ == "__main__": import uvicorn uvicorn.run(app)