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

Why do we need response_model? #938

Closed
aklauza opened this issue Feb 2, 2020 · 4 comments
Closed

Why do we need response_model? #938

aklauza opened this issue Feb 2, 2020 · 4 comments

Comments

@aklauza
Copy link

aklauza commented Feb 2, 2020

Why doesn´t FastAPI use python hints for returning types as well?

This code is more intuitive

@app.post("/items/")
async def create_item(item: Item) -> Item:
    return item

than this

@app.post("/items/", response_model=Item)
async def create_item(item: Item):
    return item
@phy25
Copy link

phy25 commented Feb 2, 2020

Please do a search here first. Possible duplicate of #875.

@aklauza
Copy link
Author

aklauza commented Feb 2, 2020

And here as well: #620. I think many people are asking about it because it makes lots of sense. I actually see as the most common scenario to return the model itself as is, rather than a special "serialization model" with different fields.

@aklauza aklauza closed this as completed Feb 2, 2020
@tiangolo
Copy link
Owner

tiangolo commented Apr 7, 2020

Thanks for the help here @phy25 🍰 🙇‍♂️

Thanks @aklauza for coming back to close the issue 👍

@tiangolo tiangolo changed the title [QUESTION] Why do we need response_model? Why do we need response_model? Feb 24, 2023
@tiangolo tiangolo reopened this Feb 28, 2023
@github-actions
Copy link
Contributor

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

@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 #7752 Feb 28, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants