Design the endpoints for orders and their line items. What do the URLs and verbs look like?
basicUse nouns, plural collections, and HTTP verbs for actions; nest only one level for true containment.
POST /orderscreates (201 +Location: /orders/42),GET /orders/42,PUT /orders/42(full replace),PATCH /orders/42(partial),DELETE /orders/42.GET /orders/42/itemsfor line items; use/items/{id}directly when items have globally unique ids.- Non-CRUD actions are modelled as sub-resources or state changes:
POST /orders/42/cancellation, notPOST /cancelOrder.
- PUT versus PATCH? PUT replaces the representation and is idempotent; PATCH applies a partial change and is not guaranteed idempotent.
- Is a deep
/a/1/b/2/c/3URL good? No, it couples clients to the hierarchy; expose resources by their own ids.