1.REST principles and resource-oriented URLs
REST organises an API around *things* rather than *actions*. A URL names a resource — `/orders/`, `/orders/57/`, `/orders/57/items/` — and the HTTP method says what to do with it. That is why `POST /orders/create/` is redundant and `POST /orders/` is not: the verb is already in the method. The other principles that matter day to day are statelessness (every request carries everything needed to serve it — no server-side conversation between calls) and a uniform interface (the same method means the same thing on every resource, so a client that understands one endpoint understands the rest). Collections are plural, identifiers go in the path, and anything that only *narrows* a collection goes in the query string.
Key features
- The URL names the resource and the method names the operation — `POST /orders/create/` says "create" twice and `DELETE /orders/57/delete/` says "delete" twice
- Collections are plural and identifiers sit in the path: `/orders/` and `/orders/57/`, never `/order/` or `/orders?id=57`
- Nest only to express containment, and only one level: `/orders/57/items/` is fine, `/customers/3/orders/57/items/9/` is a URL nobody can construct correctly
- Query parameters narrow or shape a collection (filter, sort, page); they never identify a single resource and never change what the request does
- A non-CRUD operation is either its own sub-resource (`POST /orders/57/refunds/`) or a named sub-action (`POST /orders/57/refund/`) — not a verb in the collection URL
- Trailing slashes must be consistent: DRF routers generate them by default, and `APPEND_SLASH` turns a mismatched POST into a 301 that drops the body
The same five operations, RPC-shaped and resource-shaped
- RPC-shaped — the verb is in the URL
- Every operation is a new name the client must be told about.
- The method carries no meaning — everything is POST.
- Nothing is cacheable, because a GET and a mutation look alike.
- No router can generate it; every path is hand-written.
- Adding an operation means adding vocabulary, not reusing a shape.
- Resource-oriented — the verb is the method
- One noun, five methods — a client that learns the shape once reuses it everywhere.
- GET is safe and cacheable; DELETE and PUT are idempotent. The method says so.
- A DRF router generates the whole URL set from one ViewSet.
- Non-CRUD operations become sub-resources with their own history.
- New resources cost no new vocabulary.
Command
router.register("orders", OrderViewSet, basename="order")
# generates /orders/ and /orders/{pk}/ with the standard method mappingThe URL names a thing and the method says what to do with it, so `POST /orders/create/` states the verb twice. Collections are plural, ids go in the path, query parameters only narrow. Nest one level to express containment and no more. A non-CRUD operation is either its own sub-resource — `POST /orders/57/refunds/`, which gains an id and a list endpoint — or a named sub-action, never a verb hanging off the collection URL, which collides with the detail route and moves the id out of the path where object permissions live.