pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
349 B
20 lines
349 B
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
|
|
items = {}
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app):
|
|
items["foo"] = {"name": "Fighters"}
|
|
items["bar"] = {"name": "Tenders"}
|
|
yield
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan)
|
|
|
|
|
|
@app.get("/items/{item_id}")
|
|
async def read_items(item_id: str):
|
|
return items[item_id]
|
|
|