Though I neither declare response model (None by default) neither return anything the response contains null. Is there a way to send empty body?
First check
- [ ] I used the GitHub search to find a similar issue and didn't find it.
- [ ] I searched the FastAPI documentation, with the integrated search.
- [ ] I already searched in Google "How to X in FastAPI" and didn't find any information.
https://github.com/tiangolo/fastapi/issues/449#issuecomment-523371704
Do you want to return HTTP_204_NO_CONTENT? If it is true, remove return statement from your endpoint handler.
I know in Flask you had to do something like return '', 200. You could try returning an empty string. There's probably a cleaner way, though.
This may help: https://github.com/tiangolo/fastapi/issues/717#issuecomment-583826657
@alvarogf97
Do you want to return HTTP_204_NO_CONTENT? If it is true, remove
returnstatement from your endpoint handler.
I want to return 200 and no body at all.
If I remove return response status is 200 and body is "null".
This works as I need:
return Response(status_code=HTTP_200_OK)
Thanks all!
Thanks for the help here everyone! :cake:
Thanks @symonsoft for reporting back and closing the issue :+1:
imports for the answer from @symonsoft are
from starlette.responses import Response
from starlette.status import HTTP_200_OK
Most helpful comment
This works as I need:
return Response(status_code=HTTP_200_OK)Thanks all!