Skip to content
Advertisement

Get starlette request body in the middleware context

I have such middleware

JavaScript

So the line body = await request.body() freezes all requests that have body and I have 504 from all of them. How can I safely read the request body in this context? I just want to log request parameters.

Advertisement

Answer

I would not create a Middleware that inherits from BaseHTTPMiddleware since it has some issues, FastAPI gives you a opportunity to create your own routers, in my experience this approach is way better.

JavaScript

Works as expected.

JavaScript
Advertisement