Exercise: Pagination, Filtering, Validation & Error Handling#
Goal#
Improve the API for real-world use: list endpoints with pagination, filtering (completed, search by title), and strong input validation + proper HTTP errors.
Tasks#
List endpoint with query params
GET /todos?limit=20&offset=0&completed=true&search=readReturn metadata:
total,limit,offsetanditems.
Validation
Enforce
limit[1..100],offsetโฅ 0.Title length validated in creation/update.
Error handling
Return 400 for invalid query params.
404 for missing resource with consistent error structure:
{ "detail": "...", "code": "NOT_FOUND" }.
Sorting
Support
sort=-created_atorsort=title.
OpenAPI docs
Describe each query param with examples.
Acceptance Criteria#
Pagination and filters work and are documented in
/docs.Errors are consistent with status codes.
Deliverables#
Updated source + docs.
Sample curl calls demonstrating pagination + filters.
Rubric (50 pts)#
Pagination
Filtering & sorting
Validation & error handling
Docs clarity