Practice: Design an API
A shop's endpoints.
Time to practise. Shoply needs an API for its mobile app. Users browse products, add them to a cart, and place orders. Pause, and sketch the endpoints yourself before I show mine.

- Browse products
- Fill a cart
- Place an order
One possible answer
Here's one answer. Get slash v one slash products, with search and a cursor. Get one product by ID. Post to the cart to add an item. Get the cart. And post slash orders, with an idempotency key header, so a retried checkout never creates two orders.
| Endpoint | Purpose |
|---|---|
| GET /v1/products?q=&after= | search, paginated |
| GET /v1/products/{id} | one product |
| POST /v1/cart/items | add to cart |
| GET /v1/cart | see the cart |
| POST /v1/orders | checkout (Idempotency-Key) |
What we used
Notice what we used from earlier lessons. Plural nouns, and a version in the path. Cursor pagination for long lists. Proper verbs. And an idempotency key on the one call where a duplicate would really hurt, placing an order.
| key | value |
|---|---|
| Nouns + /v1 | clean and versioned |
| Cursor | for long lists |
| Verbs | GET reads, POST creates |
| Idempotency key | on checkout |
Summary
A good API design combines clear resources, versions, pagination, and idempotency. Next, a quick quiz on networking and APIs.
Key takeaways- Resources first
- Paginate lists
- Protect checkout