Practice: design REST endpoints for given requirements
A review of this module. Skip it if you feel confident; the next module does not need it.
Fix the mistakes
The slips that cost marks in this module. Spot each one, then check the fix.
A client hands you a page of requirements and a deadline. Before any code, you need the endpoints: the URLs, methods, statuses and errors that a mobile app can rely on.
Requirements to resources
A resource is a noun the client reads or changes, such as a product or an order, and it has its own URL like /orders/14.
Underline the nouns the client works with. In "customers order products from sellers and can cancel an order before it ships" they are customer, order, product and seller. Each noun becomes a plural collection (/sellers) with items by id (/sellers/12).
A thing that only exists inside another one gets one level of nesting: a product belongs to a seller, so /sellers/12/products. Never go deeper; /sellers/12/products/5/reviews becomes /products/5/reviews.
Verbs in the requirements ("cancel", "ship") are state changes of a resource, not new URLs with verbs. Model them as a status field changed by a small action endpoint (POST /orders/14/cancel, as ShopLite does) or by PATCH on the status; pick one style and use it everywhere.
- Nouns → collections; ids → items; "belongs to" → one level of nesting.
- Verbs → methods or a few named actions on one resource.
- Write down what is NOT in v1 (for example, deleting orders) and why.
Endpoint tables with methods, statuses and example bodies
An endpoint table is the whole design on one page: for every operation its method, URL, request fields, success status and possible errors.
The table below is the marketplace design on one page, followed by one request and its response.
Example 1 · Marketplace API: the endpoint table and one exchange
Marketplace API v1, base URL /api/v1Method URL Body Success ErrorsGET /sellers - (city, category, page, size, sort) 200 page 400GET /sellers/{id} - 200 seller 404GET /sellers/{id}/products - 200 array 404POST /orders customerId, sellerId, 201 + Location 400, 409 out-of-stock, addressId, items[{productId, 422 (unknown seller, quantity}] item of another seller)GET /orders/{id} - 200 order 404POST /orders/{id}/cancel - 200 order 404, 409 invalid-stateGET /customers/{id}/orders - (status, page, size, sort) 200 page 400, 404Order status: PLACED -> PACKED -> SHIPPED -> DELIVERED, or PLACED/PACKED -> CANCELLEDPOST /api/v1/orders HTTP/1.1
Content-Type: application/json
{ "customerId": 7, "sellerId": 12, "addressId": 3,
"items": [ { "productId": 41, "quantity": 2 } ] }
HTTP/1.1 201 Created
Location: http://localhost:8080/api/v1/orders/230
Content-Type: application/json
{ "id": 230, "customerId": 7, "sellerId": 12, "addressId": 3,
"status": "PLACED", "orderedAt": "2026-10-16T13:10:00+05:30",
"items": [ { "productId": 41, "name": "Notebook", "quantity": 2,
"unitPrice": 90.00, "lineTotal": 180.00 } ],
"total": 180.00 }What this code does
- Sellers, products, orders and customers are the nouns; the product list is nested once under its seller, and "cancel" is one action endpoint like ShopLite's.
- The example exchange proves the design: the create answers 201 with
Location, and the order copies each item's price so later price changes do not change old orders.
Every row follows the same conventions: GET reads (200), POST to a collection creates (201 + Location + the new item), PUT replaces and PATCH changes some fields (200 + the item), DELETE removes (204, no body). If you cannot write the JSON of a response, the design is not finished.
Three rules for every body:
- Clients never send
idin a create body; the server makes it. - Money is an exact decimal number, dates are ISO-8601 with an offset.
- Field names are camelCase and enums UPPER_CASE, one style for the whole API.
Order of execution
Order the design steps
Put the steps of a REST design in the order you do them.
List endpoints with filters, sorting and pages
An allow-list is the fixed set of fields a list may be sorted or filtered by; any other field is rejected with a 400 that names it.
Any list that grows with traffic (orders, bookings, sellers) is paged: page (from 0), size (with a maximum, say 100) and sort (field,asc|desc from an allow-list). Filters are query parameters named after fields: GET /sellers?city=Pune&category=ELECTRONICS&sort=rating,desc.
Decide the edge cases in the design, not in the code: a filter that matches nothing is a 200 with an empty page, a bad size or an unknown sort field is a 400 that names the parameter, and ties are broken by id so pages never overlap. Small fixed lists (the menu of one seller) may stay plain arrays.
Predict the output
Predict the status
The design says size is 1-100 and sort is limited to rating, deliveryDays and name.
Round 1 of 3
What does the server answer?
Error cases and their Problem Details bodies
Problem Details is the standard error body (application/problem+json) with type, title, status, detail and instance, so every error has the same shape.
Four questions pick the status of an error. The request after the picture is valid but the product is sold out, so it gets a 409.
Example 2 · One error case: an item that is sold out
POST /api/v1/orders HTTP/1.1Content-Type: application/json{ "customerId": 7, "sellerId": 12, "addressId": 3, "items": [ { "productId": 44, "quantity": 1 } ] }HTTP/1.1 409 Conflict
Content-Type: application/problem+json
{
"type": "https://market.example/problems/out-of-stock",
"title": "Product out of stock",
"status": 409,
"detail": "Desk Lamp is out of stock.",
"instance": "/api/v1/orders",
"productId": 44
}What this code does
- The request is valid and every id exists, but the item clashes with the current state (sold out), so it is 409, not 400 or 422.
- The extension
productIdlets the app highlight the exact product;detailis safe to show the customer.
Every error uses the same Problem Details body: type, title, status, detail, instance, plus extensions such as errors for validation. Clients branch on type, so give each kind of error its own stable type URL.
Finish up
Mark complete & continue
Next: Practice: spot the mistakes in a badly designed API