mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-23 22:29:34 -05:00
Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com> Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
24 lines
461 B
Python
24 lines
461 B
Python
from datetime import datetime
|
|
from typing import Union
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.encoders import jsonable_encoder
|
|
from pydantic import BaseModel
|
|
|
|
fake_db = {}
|
|
|
|
|
|
class Item(BaseModel):
|
|
title: str
|
|
timestamp: datetime
|
|
description: Union[str, None] = 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
|