Pre-conditionsΒΆ

The pre-conditions are the conditions which must hold prior to the execution of the endpoint.

You specify the pre-conditions using the decorator require.

Here is a snippet demonstrating how to specify a pre-condition (see the full example):

from fastapi_icontract import require

@app.get("/books_in_category", response_model=List[Book])
@require(
    has_category,
    status_code=404,
    description="The category must exist."
)
async def books_in_category(category: str) -> Any:
    ...