Description
As the database grows, returning every task or user in one response becomes a problem. Add skip and limit pagination to both list endpoints.
What to do
Acceptance Criteria
GET /tasks/?skip=0&limit=5 returns at most 5 tasks starting from the first
GET /tasks/?skip=5&limit=5 returns the next 5
- Same behaviour for
/users/
- Default behaviour (no params) returns the first 10 results
Hints
- FastAPI handles query params automatically when declared as function arguments
- SQLAlchemy:
db.query(Task).offset(skip).limit(limit).all()
Difficulty
🟡 Intermediate
Description
As the database grows, returning every task or user in one response becomes a problem. Add
skipandlimitpagination to both list endpoints.What to do
skip: int = 0andlimit: int = 10query params toGET /tasks/skip: int = 0andlimit: int = 10query params toGET /users/.offset(skip).limit(limit)Acceptance Criteria
GET /tasks/?skip=0&limit=5returns at most 5 tasks starting from the firstGET /tasks/?skip=5&limit=5returns the next 5/users/Hints
db.query(Task).offset(skip).limit(limit).all()Difficulty
🟡 Intermediate