Skip to content

Instantly share code, notes, and snippets.

@danielballan
Created March 10, 2023 15:21
Show Gist options
  • Save danielballan/709b96f8e5fd56e1393c76f84c0b4358 to your computer and use it in GitHub Desktop.
Save danielballan/709b96f8e5fd56e1393c76f84c0b4358 to your computer and use it in GitHub Desktop.
Middle exploration

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 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?

from fastapi import FastAPI, Request
app = FastAPI()
@app.get("/data")
def data():
return [1, 2, 3]
if __name__ == "__main__":
import uvicorn
uvicorn.run(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment