Skip to content
Discussion options

You must be logged in to vote

It's for optimization purposes. This can be useful if your return data is big and you are sure that it's serializable with JSON.

As it's said in the documentation, by returning ORJSONResponse([{"item_id": "Foo"}]) you can

avoid the extra overhead that FastAPI would have by passing your return content through the jsonable_encoder before passing it to the response class.

https://fastapi.tiangolo.com/advanced/custom-response/#use-orjsonresponse

ORJSONResponse is inherited from the Response class. So, in this case you will save some execution time by not passing your return content through the jsonable_encoder. If you just return [{"item_id": "Foo"}], FastAPI will pass it through the jsonab…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants