1.REST and resource modeling
REST models an API as nouns (resources — /orders, /users/42) manipulated by a small, uniform set of HTTP methods, instead of one URL per action (/getOrder, /createOrder) — resource modeling is the design skill of choosing what counts as a resource and how they nest.
Key features
- A resource is a noun with a stable identity — /orders/4821, not an action like /getOrderById
- Collections are plural (/orders); a specific member is the collection plus an identifier (/orders/4821)
- Nesting expresses ownership: /users/42/orders is "orders belonging to user 42" — do not nest more than 2 levels deep, it gets unreadable
- An action that genuinely is not CRUD (like "cancel an order") is still modeled as a resource: POST /orders/4821/cancellation, not POST /cancelOrder
- HTTP semantics (which method, which status code) is the mechanism resource design relies on — see Web and HTTP Fundamentals for the method/status vocabulary itself
Action-style vs. resource-style URLs
- Action style (avoid)
- POST /createOrder
- POST /cancelOrder?id=4821
- A new endpoint per action
- Resource style (REST)
- POST /orders
- POST /orders/4821/cancellation
- The same uniform verbs, every noun
Command
# resource-style route table, framework-agnostic
routes = {
('GET', '/orders'): list_orders,
('POST', '/orders'): create_order,
('GET', '/orders/{id}'): get_order,
('PUT', '/orders/{id}'): replace_order,
('DELETE', '/orders/{id}'): delete_order,
('GET', '/users/{user_id}/orders'): list_orders_for_user, # nested = ownership
}Model nouns (resources), not verbs — a genuinely non-CRUD action still becomes a sub-resource (POST .../cancellation), and nesting should stay at most 2 levels deep.