Description
How can I [...]?
I'm trying to figure out how to use one endpoint for multiple response content_types? I want to create an /export API endpoint and be able to dump (from memory) responses such as application/json, application/yaml or application/zip based on the content-type requested.
Everything I've seen so far is just for a single response type - though I've probably missed something because this is one of the best documented projects I've used.
Documenting this in OpenAPI is something is currently not supported, although you can return anything you want if you use a Starlette response: https://www.starlette.io/responses/
But I'll have it in mind while checking how to document multiple response types.
[...] though I've probably missed something because this is one of the best documented projects I've used.
That's great to hear! Thanks! ...although it is actually the case that it is not documented (yet) :see_no_evil:
Thanks!
It is now possible to add a parameter responses, in it you can declare additional OpenAPI responses or extend the main one, this includes other media types/content types, other status codes, headers, examples, description, etc: https://fastapi.tiangolo.com/tutorial/additional-responses/
The specific example with a different media type (the example is with an image) is here: https://fastapi.tiangolo.com/tutorial/additional-responses/#additional-media-types-for-the-main-response
It is available in version 0.12.0 :tada: :rocket:
It is now possible to add a parameter
responses, in it you can declare additional OpenAPI responses or extend the main one, this includes other media types/content types, other status codes, headers, examples, description, etc: https://fastapi.tiangolo.com/tutorial/additional-responses/The specific example with a different media type (the example is with an image) is here: https://fastapi.tiangolo.com/tutorial/additional-responses/#additional-media-types-for-the-main-response
It is available in version
0.12.0馃帀 馃殌
@tiangolo link provided in your answer give me an 404 error can you provide the correct link thanks !
@tiangolo Maybe the URL should be https://fastapi.tiangolo.com/advanced/additional-responses/ ?
Yep, thanks for the link @jbkoh . I moved the docs when separating the tutorial in basic and advanced.
looks good now thanks @tiangolo