Resource Design
What a “resource” is in APIs
- A resource is anything with an identity you expose over the API: user, order, invoice, subscription, etc.
- Resources should map to domain concepts, not to every database row or internal job unless that is your product surface.
- Collections (
/orders) and items (/orders/{id}) are the usual REST pattern.
Nouns vs verbs in endpoints
- Prefer nouns in paths (
/orders, /orders/{id}) and express actions with HTTP methods or sub-resources (/orders/{id}/cancel is still debated; some use POST to a verb-like subpath, others model state transitions as PATCH).
- Avoid a zoo of verb endpoints (
/createOrder, /getOrder) when HTTP already encodes verbs.
- Exception: RPC-style operations (reports, searches) sometimes fit better as
POST /searches or a dedicated RPC layer.
Naming conventions (/users, /orders)
- Use plural nouns for collections (
/users, /orders) for consistency.
- Use kebab-case or lowercase path segments; avoid spaces and ambiguous casing.
- Keep URLs readable in logs and stable for years (changing names is a breaking change).
Hierarchical resources (/users/{id}/orders)
- Nest when the child cannot exist meaningfully without the parent in your domain (
/users/{id}/orders).
- Avoid deep trees (
/a/b/c/d/e) that mirror internal storage too closely; flatten when the hierarchy does not help clients.
- Consider pagination and filtering at the collection level (
/users/{id}/orders?status=open).