liveBook · Manning

State transition

As explained in API Design Patterns

A state transition is a change of a resource from one status or condition to another.

A state transition changes a resource from one condition to another, such as moving an email from draft to sent. Although an update method can change the stored state field, it obscures the difference between editing data and performing an action. section 9.1.1

Treat transitions as distinct actions when changing state carries meaning or side effects. Updating an email's state to sent can surprise users, makes a service-managed field appear client-controlled, and conflates two conceptual operations. section 9.1.1

Marking an email as sent

The tempting design retrieves an email and calls UpdateEmail({id: email.id, state: 'sent'}). A clearer API would expose a dedicated action for sending, keeping ordinary updates for fields such as the subject. section 9.1.1

How API Design Patterns covers it

How deep it goes
Explains the conceptual distinction from scalar updates and identifies confusion and side effects, but stops short of implementing a custom action.
Examples
Uses an email moving from draft to sent, with UpdateEmail setting state to sent as the problematic design.
What it assumes
Assumes familiarity with standard API methods, resource fields, and scalar updates.
What you can do after
Apply custom actions to represent meaningful state changes rather than disguising them as ordinary field updates.
How it connects
Connects state transitions with API resources, standard methods, update methods, scalar fields, and custom methods.

Also explained in

Compare how 7 books explain state transition →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.