This is because by default, FastAPI will inspect every item inside and make sure it is serializable with JSON, using the same JSON Compatible Encoder explained in the tutorial. Import the Response class (sub-class) you want to use and declare it in the path operation decorator.įor large responses, returning a Response directly is much faster than returning a dictionary. Use ORJSONResponse ¶įor example, if you are squeezing performance, you can install and use orjson and set the response to be ORJSONResponse. If you use a response class with no media type, FastAPI will expect your response to have no content, so it will not document the response format in its generated OpenAPI docs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |