mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-16 12:31:57 -04:00
✨ Add support for function return type annotations to declare the response_model (#1436)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from typing import Any
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -13,5 +15,13 @@ class Item(BaseModel):
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item)
|
||||
async def create_item(item: Item):
|
||||
async def create_item(item: Item) -> Any:
|
||||
return item
|
||||
|
||||
|
||||
@app.get("/items/", response_model=list[Item])
|
||||
async def read_items() -> Any:
|
||||
return [
|
||||
{"name": "Portal Gun", "price": 42.0},
|
||||
{"name": "Plumbus", "price": 32.0},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user