Commit 0d2e0511 authored by Roman Desyatskii's avatar Roman Desyatskii

Created router

parent 97dec368
from typing import Annotated
import fastapi
from fastapi import APIRouter, Path
from pydantic import BaseModel
router = APIRouter(prefix='/api')
class Item(BaseModel):
name: str
description: str | None = None
price: float
tax: float | None = None
@router.post('/items/')
async def create_item(item: Item):
return item
@router.put('/items/{item_id}')
async def put_item(
item_id: Annotated[int, Path(title="The ID of the item to get", ge=0, le=1000)],
q: str | None = None,
item: Item | None = None,
):
results = {"item_id": item_id}
if q:
results.update({'q': q})
if item:
results.update({"item": item})
return results
@router.get('hello-name/{name}')
async def get_hello_name(
name: str = fastapi.Path(..., title='Title name!'),
):
return {'response': f'Hello {name} glad to see you!'}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment