Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple response content types in one endpoint? #82

Closed
wshayes opened this issue Mar 15, 2019 · 7 comments
Closed

Multiple response content types in one endpoint? #82

wshayes opened this issue Mar 15, 2019 · 7 comments
Labels
question Question or problem question-migrate

Comments

@wshayes
Copy link
Sponsor Contributor

wshayes commented Mar 15, 2019

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.

@wshayes wshayes added the question Question or problem label Mar 15, 2019
@wshayes wshayes changed the title [QUESTION] Multiple response content types? [QUESTION] Multiple response content types in one endpoint? Mar 15, 2019
@tiangolo
Copy link
Owner

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) 🙈

@wshayes
Copy link
Sponsor Contributor Author

wshayes commented Mar 27, 2019

Thanks!

@wshayes wshayes closed this as completed Mar 27, 2019
@tiangolo
Copy link
Owner

tiangolo commented Apr 5, 2019

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 🎉 🚀

@binary-signal
Copy link

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 !

@jbkoh
Copy link

jbkoh commented Feb 17, 2020

@tiangolo
Copy link
Owner

Yep, thanks for the link @jbkoh . I moved the docs when separating the tutorial in basic and advanced.

@binary-signal
Copy link

looks good now thanks @tiangolo

@tiangolo tiangolo changed the title [QUESTION] Multiple response content types in one endpoint? Multiple response content types in one endpoint? Feb 24, 2023
@tiangolo tiangolo reopened this Feb 28, 2023
Repository owner locked and limited conversation to collaborators Feb 28, 2023
@tiangolo tiangolo converted this issue into discussion #8240 Feb 28, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Question or problem question-migrate
Projects
None yet
Development

No branches or pull requests

4 participants