Skip to content

app

A minimal FastAPI application.

read_root async

read_root() -> dict[str, str]

Handles the / route and returns a JSON response.

Source code in src/deadnews_template_python/app.py
18
19
20
21
@app.get("/")
async def read_root() -> dict[str, str]:
    """Handles the `/` route and returns a JSON response."""
    return HELLO_WORLD

read_health async

read_health() -> dict[str, str]

Handles the /health route and returns a JSON response.

Source code in src/deadnews_template_python/app.py
24
25
26
27
@app.api_route("/health", methods=["GET", "HEAD"])
async def read_health() -> dict[str, str]:
    """Handles the `/health` route and returns a JSON response."""
    return HEALTH

read_item async

read_item(item_id: str) -> dict[str, str]

Handles the /items/{item_id} route and returns the corresponding value as a JSON response.

Parameters:

Name Type Description Default
item_id str

The ID of the item to retrieve from the ITEMS dictionary.

required

Returns:

Type Description
dict[str, str]

The corresponding value from the ITEMS dictionary as a JSON response.

Raises:

Type Description
HTTPException

If the item_id is not found in the ITEMS dictionary, raise an HTTPException with a status code of 404.

Source code in src/deadnews_template_python/app.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@app.get("/items/{item_id}")
async def read_item(item_id: str) -> dict[str, str]:
    """Handles the `/items/{item_id}` route and returns the corresponding value as a JSON response.

    Args:
        item_id: The ID of the item to retrieve from the ITEMS dictionary.

    Returns:
        The corresponding value from the ITEMS dictionary as a JSON response.

    Raises:
        HTTPException: If the item_id is not found in the ITEMS dictionary, raise an HTTPException with a status code of 404.
    """
    if item_id not in ITEMS:
        raise HTTPException(status_code=404, detail="Item not found.")

    return {"item": ITEMS[item_id]}