Chapter 1 · Practice 1 of 4
Model resources as nouns and let the method be the verb
From Resources and URLs
Why it matters
In HTTP, the method already says what to do. The URL should say what to do it to. URLs like /getOrders, /createOrder and /deleteOrder?id=7 duplicate the method in the path and leave clients guessing the name of every operation.
| Instead of | Use |
|---|---|
GET /getOrders | GET /orders |
POST /createOrder | POST /orders |
POST /deleteOrder?id=7 | DELETE /orders/7 |
GET /getOrderItems?orderId=7 | GET /orders/7/items |
Use plural nouns for collections (/orders) and an identifier for one member (/orders/7). Clients can then guess most URLs without reading the docs.
Do
- Use plural nouns for collections
- Use lowercase, hyphen-separated path segments
- Keep the same name for a concept across every endpoint