Category: fastapi

Problem

Create a typed JSON API endpoint.

Solution

  @app.get("/items/{item_id}")
def get_item(item_id: int):
    return {"id": item_id}
  

Notes

  • Adapt variable names and paths to your project
  • Add error handling for production use
  • See related chapters in the Learning Path