Skip to content
Ameen Abozaid
Planned lessonJNR-018-L04

Modeling actions (checkout, cancel)

  • Lesson 4 of 6
  • Junior
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 /orders to check out a cart.
  • Model state changes as a sub-resource or a state field: POST /orders/7/cancellation, or PATCH /orders/7 with 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 (or PUT/PATCH), never GET.
  • Document which state transitions are allowed; an invalid one returns 409.
Draft outline details

Demonstration

text
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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.