API Design · question
Question 30 of 48
What are API design anti-patterns to avoid?
Related concept
Thinking in resources: what REST actually is
REST is constraints, not JSON over HTTP: address resources, let methods decide the action, send hypermedia links to what's next and more.
For this question · chapter 2 of 3
2/3
Six endpoints become four addresses
Six endpoints become four addresses
- What does 'the uniform interface' mean. The six POST endpoints on the left are each named after an action, so that API ignores the uniform interface. Every feature got its own name, which felt natural but it has its cost.
- Instead, name the thing and you got one address, /users/123. The three user endpoints become methods on that address: GET reads the user, PUT replaces the user, DELETE removes the user. Six endpoints will become three, all on that one address. The method carries the action, and the URL is the name of the resource.
- The collection for the item is the same noun, plural - /users. Finding a user by email is not an action worth a name. That search is a filter on the collection, GET /users?email=. The collection keeps one address, and you can add as many filters later.
- Orders belong to a user, so /users/123/orders sits one level under /users/123 and allows GET and POST actions. The path defines who owns what. The left column, the list of actions, is empty now. Every action has an address and a method.
- Be careful of nesting. The path /users/123/orders/456/items/7 repeats ids that already identify things on their own. Nesting is a habit that does not know where to stop. An order has its own id, so /orders/456 stands alone and items sit under that path. So usually, nest one level to show ownership, and stop there.
- The address tree should read like the domain: users have orders. And a client should be able to guess addresses that match your entities. A verb in a path means you are calling a function over HTTP, not addressing a resource.
Chapter 2 · step 1 of 6
What does 'the uniform interface' mean. The six POST endpoints on the left are each named after an action, so that API ignores the uniform interface. Every feature got its own name, which felt natural but it has its cost.
© LearnThatStack - diagrams may not be republished without permission.
Want a quick review of the fundamentals? See the API Design cheatsheet.
Pro · $10/mo
37 of 48 API Design answers are in Pro.
Full answers, code samples, AI explanations - simpler, deeper, or as an interactive diagram. Cancel anytime.
- Full answers + code
- AI explain - simpler, deeper, or visualized
- 1,000 AI credits / month
- Cancel anytime