FastAPI - Middleware and Hooks
Given this middleware in FastAPI:
What will be printed when a client requests GET /hello?
from fastapi import FastAPI
from starlette.middleware.base import BaseHTTPMiddleware
app = FastAPI()
class PrintMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
print("Before request")
response = await call_next(request)
print("After request")
return response
app.add_middleware(PrintMiddleware)
@app.get("/hello")
async def hello():
return {"msg": "Hello"}What will be printed when a client requests GET /hello?
