Practice: spot the mistakes in a badly designed API
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 teammate asks you to review an API that already works: the app loads, but every new client needs special cases and monitoring shows no errors. Where do you start?
Verbs in URLs, GET that changes data, 200 for every error
Here is a working API that every client dislikes. Read it line by line and count the mistakes before you read the findings.
Example 1 · CampusShop v0: the API under review
GET /getAllOrders -> 200 [ ...all 48,000 orders... ]POST /createOrder -> 200 { "success": true, "orderID": 230 }GET /order_details?id=230 -> 200 { "order_id": 230, "Status": "placed", "created": "16/10/2026 1:10 PM", "customer": { "name": "Ravi", "passwordHash": "$2a$10$..." }, "internalNotes": "VIP, free shipping" }GET /orders/230/delete -> 200 { "success": true }POST /updateOrderStatus -> 200 { "success": false, "error": "java.lang.IllegalStateException: status DELIVERED at OrderService.java:88" }Findings 1. Verbs in URLs: getAllOrders, createOrder, order_details, delete, updateOrderStatus. 2. GET /orders/230/delete changes data: a link preview or crawler deletes the order. 3. 200 for errors: success=false with status 200 hides failures from clients and monitoring. 4. Create returns 200 without Location; the id is called orderID here and order_id elsewhere. 5. Mixed naming: order_id, orderID, Status; status value in lowercase. 6. Date "16/10/2026 1:10 PM" has no time zone and is ambiguous (16 Oct or day 16 of month 10?). 7. No pagination on the order list. 8. Leaked fields: passwordHash and internalNotes. 9. Stack trace details (class name, file, line) in an error body.
What this code does
- Each line of the API shows at least one mistake; reading it once per kind of mistake (URLs, methods, statuses, names, dates, lists, leaks) finds all nine.
- The findings say why each one matters, which is what convinces a team to change a working API.
Three mistakes come first:
- Verbs in URLs (
/getAllOrders,/createOrder,/orders/5/delete) repeat what the method says; use nouns plus methods:GET /orders,POST /orders,DELETE /orders/5. - A GET that changes data is dangerous: browsers prefetch links, crawlers follow them and clients retry GETs freely. Any change is
POST,PUT,PATCHorDELETE. - 200 for every error (
200 {"success": false}) hides failures from monitoring, retries and caches; use the real 4xx/5xx status with a Problem Details body.
Find the bug
Find the dangerous line
Click the line a reviewer must fix first.
Which endpoint could a link preview or crawler run by accident?
Round 1 of 2Inconsistent naming, error shapes and date formats
An API should look like one person wrote it. Mixed field styles (order_id, orderID, Status), two error shapes ({"error": ...} here, {"msg": ...} there) and dates such as 16/10/2026 1:10 PM in one place and 1760600400 in another force every client to special-case each endpoint.
The fix is a written convention applied everywhere: camelCase fields, id for ids, UPPER_CASE enums, ISO-8601 dates with an offset (2026-10-16T13:10:00+05:30), money as an exact decimal, and one Problem Details shape for every error.
Fix the error
Make the response consistent
A client fails on the response. Pick the line that fixes the contract.
Round 1 of 2
The new client expects the same id field everywhere.
Error
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "order_id" (class OrderResponse), not marked as ignorable
Missing pagination, leaked internal fields and stack traces
A list without paging (GET /getAllOrders returning 48,000 orders) works in the demo and fails in production: slow queries, huge responses and timeouts. Add page, size with a maximum, and an allow-listed sort.
Leaked fields such as passwordHash, internalNotes or costPrice appear when the API serialises the database entity directly. Send a response record with only the fields the contract lists. Stack traces, exception class names and SQL in error bodies tell attackers your stack and schema; log them on the server and send a generic detail with a 500.
Rewriting the API correctly and explaining each fix
Problem Details is the standard error body (application/problem+json) with type, title, status, detail and instance, so every error has the same shape.
The rewrite below fixes all nine findings. Compare each line with the first API.
Example 2 · CampusShop v1: the rewrite
GET /api/v1/orders?status=&page=0&size=20&sort=orderedAt,desc 200 page of order summariesPOST /api/v1/orders 201 + Location + orderGET /api/v1/orders/{id} 200 order | 404DELETE /api/v1/orders/{id} 204 | 404 | 409 in-usePOST /api/v1/orders/{id}/deliver 200 order | 404 | 409 invalid-stateErrors: application/problem+json { type, title, status, detail, instance }GET /api/v1/orders/230
HTTP/1.1 200 OK
Content-Type: application/json
{ "id": 230, "customerId": 7, "customerName": "Ravi", "status": "PLACED",
"orderedAt": "2026-10-16T13:10:00+05:30", "total": 180.00 }
POST /api/v1/orders/230/deliver (order is already DELIVERED)
HTTP/1.1 409 Conflict
Content-Type: application/problem+json
{ "type": "https://campusshop.example/problems/invalid-state",
"title": "Invalid state change", "status": 409,
"detail": "Order 230 is already DELIVERED.", "instance": "/api/v1/orders/230/deliver" }What this code does
- Nouns plus methods, real statuses, one naming style, ISO-8601 dates and a paged list fix findings 1-7.
- The response record has only contract fields (no
passwordHash, no notes) and the error has a safedetail, fixing findings 8-9; the stack trace goes to the server log.
A good review has three parts: a finding list (endpoint, problem, why it matters), the rewritten endpoint table and a migration note for clients already using the old API. Explain each fix with its effect: "GET must not delete, because a link preview would delete the order" convinces a team; "GET must be safe" alone rarely does.
Three habits make a review easy to act on:
- Group findings by kind so the same fix is applied everywhere.
- Keep the old endpoints working under the old path until clients move (a v2 next to v1).
- Show one before and after exchange for the most important fix.
Finish up
Mark complete & continue
Next: HTTP and REST interview questions