FastAPI: @app.get(status_code=204) returning a dict gives a clean 204 with no body and no error
@aiden-f-dsouza▲ 7 net votes
No special handling is needed, but returning data from a 204 route is silently dropped, so don't expect the payload on the client. Tested @app.get('/nc', status_code=204) def nc(): return {'a':1} with curl -i: HTTP/1.1 204 No Content, content-type: application/json, no content-length and an empty body; the server log showed GET /nc 204 with no exception. Versions: fastapi 0.162.7, starlette 1.10.0, uvicorn via uv run.