BE1: Designing APIs that last

Lesson 3 of 5 · reading 15–25 minutes; practice and project time is on the module page

Lists, filters and versions

🎯You'll be able to

Design list endpoints that page through large results, filter predictably and change over time without breaking callers.

🏠The everyday picture

A library catalogue doesn't hand you every book at once. It shows twenty, with "next page", and you can filter by author. When the library adds a new field to its cards, old searches still work.

📘What it really is

📝A worked example

A cursor design for GET /v1/me/orders?limit=2 (the kit itself only needs limit) returns:

{"orders": [{"id": 120044, "placed_at": "2026-11-01T07:12:00Z", "total_paise": 26000},
            {"id": 119980, "placed_at": "2026-11-01T06:40:00Z", "total_paise": 13000}],
 "next": "/v1/me/orders?limit=2&before=2026-11-01T06:40:00Z_119980"}

The cursor combines the time and the ID, so two orders placed in the same second still page correctly. The query behind it is WHERE (placed_at, id) < ($1, $2) ORDER BY placed_at DESC, id DESC LIMIT $3, and an index on (customer_id, placed_at, id) keeps it fast however deep the customer scrolls.

🌍Where it's used

📝Case scenario

An API renames total to total_paise in place, to make the unit clear. Overnight, a partner's invoice tool shows ₹0 on every invoice because total is missing. The safer path: add total_paise alongside total, mark total as deprecated in the documentation, tell callers, and remove it only in /v2/.

🖱️Try it

Add limit handling to the kit's GET /v1/me/orders (default 20, at most 50). Then sketch, on paper, the cursor version above. Success: ?limit=500 returns at most 50 orders, and ?limit=-3 returns a sensible default.

⚠️Common mistakes

🛠️For your project

Project 1 test 7 calls GET /v1/me/orders with extra parameters; your list must stay limited to the signed-in customer's orders.

✅Quick check

Why is a cursor more reliable than an offset for a feed that keeps growing?

Show the answer

New items shift every offset, so pages repeat or skip items; a cursor continues after a known item.

Is adding a new field to a response a breaking change?

Show the answer

Usually not: callers that don't know the field ignore it. Removing or renaming a field is.

← PreviousErrors people and programs can act on
ProLearners Assist