|
|
|
@ -3,21 +3,22 @@ from typing import Annotated |
|
|
|
from fastapi import FastAPI, Header, HTTPException |
|
|
|
from pydantic import BaseModel |
|
|
|
|
|
|
|
fake_secret_token = "coneofsilence" |
|
|
|
|
|
|
|
fake_db = { |
|
|
|
"foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"}, |
|
|
|
"bar": {"id": "bar", "title": "Bar", "description": "The bartenders"}, |
|
|
|
} |
|
|
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel): |
|
|
|
id: str |
|
|
|
title: str |
|
|
|
description: str | None = None |
|
|
|
|
|
|
|
foo_item = Item(id="foo", title="Foo", description="There goes my hero") |
|
|
|
bar_item = Item(id="bar", title="Bar", description="The bartenders") |
|
|
|
|
|
|
|
fake_secret_token = "coneofsilence" |
|
|
|
|
|
|
|
fake_db: dict[str, Item] = { |
|
|
|
"foo": foo_item, |
|
|
|
"bar": bar_item, |
|
|
|
} |
|
|
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
|
|
@app.get("/items/{item_id}", response_model=Item) |
|
|
|
async def read_main(item_id: str, x_token: Annotated[str, Header()]): |
|
|
|
|