Modeling actions (checkout, cancel)
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
model operations that are not plain CRUD.
Planned topics
- Prefer to model the result as a resource:
POST /ordersto check out a cart. - Model state changes as a sub-resource or a state field:
POST /orders/7/cancellation, orPATCH /orders/7with a new status. - If it really is a command, a clear action sub-path is acceptable:
POST /orders/7/cancel. Be consistent. - Actions that change state use
POST(orPUT/PATCH), neverGET. - Document which state transitions are allowed; an invalid one returns
409.
Draft outline details
Demonstration
POST /carts/9/checkout -> 201, Location: /orders/42
POST /orders/42/cancel -> 200 (or 409 if already shipped)Check your understanding
Why not GET /orders/42/cancel?
Show answer
GET must be safe; cancelling changes state.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.