mirror of
https://github.com/fastapi/fastapi.git
synced 2026-10-22 18:06:17 -04:00
📝 Add docs about returning a response directly and encoder (#184)
This commit is contained in:
1 parent
192ebba2a2
commit
2b7f201a44
7 files changed
+195
-51
No files matched your search
@@ -0,0 +1,22 @@
|
||||
from datetime import datetime
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from pydantic import BaseModel
|
||||
|
||||
fake_db = {}
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
title: str
|
||||
timestamp: datetime
|
||||
description: str = None
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.put("/items/{id}")
|
||||
def update_item(id: str, item: Item):
|
||||
json_compatible_item_data = jsonable_encoder(item)
|
||||
fake_db[id] = json_compatible_item_data
|
||||
Reference in new issue
Block a user