A typed path parameter

Take your time, follow the code and check your understanding.

The codeHTTP and validation
@app.get("/products/{product_id}")
def product(product_id: int):
    return {"id": product_id}

# GET /products/not-a-number
Your answer4 min · no timer
What needs fixing?

Show solution and explanation

FastAPI validates a declared integer path parameter before calling the handler. A non-integer value causes a 422 response.

The framework returns a validation error (422).