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