-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

FastAPI Cookbook
By :

In any RESTful API, providing the functionality to filter data based on certain criteria is essential. In this recipe, we’ll enhance our Task Manager API to allow users to filter tasks based on different parameters and create a search endpoint.
The filtering functionality will be implemented in the existing GET /tasks
endpoint to show how to overcharge an endpoint, while the search functionality will be shown on a brand-new endpoint. Make sure you have at least the CRUD operations already in place before continuing.
We will start by overcharging GET /tasks
endpoint with filters. We modify the endpoint to accept two query parameters: status
and title
.
The endpoint will then look like the following:
@app.get("/tasks", response_model=list[TaskWithID]) def get_tasks( status: Optional[str] = None, title: Optional[str] = None, ):...