Bitpath

Boss lesson · Unit 01

Design a small API

Orders for a shop: URLs, bodies, filters, and paging that survives change

13 exercisesabout 3 min

What you practise

  • Orders for a shop: URLs, request and response bodies, filtering and sorting, offset against cursor pagination and what breaks each

Try a question from this lesson

Pick one

A shop needs four things: list my orders, place an order, look at one order, cancel one. Which set of endpoints fits?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

The path names it, the query narrows it

Filtering, sorting and paging do not make new resources. They are views of one collection, so they go in the query string.

Pick conventions once and use them everywhere: a field name to filter by, sort with a leading - for descending, limit for the page size.

GET /orders?status=shipped
GET /orders?sort=-createdAt
GET /orders?status=shipped&limit=20

Concept

Cursors: continue after this one

A cursor names the last item you saw instead of counting how many to skip: "two more, after order 40".

Inserts and deletes elsewhere in the list cannot shift that anchor. The reply carries the cursor for the next page.

The price: you can only go forward, never jump to page 7.

GET /orders?limit=2&after=40

{"data": [{"id": "30"}, {"id": "20"}],
 "next": "20"}

10 more exercises in the app

  • 2× fill the blanks
  • 4× multiple choice
  • 2× type the answer
  • 1× true or false
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy