Card 11/ 11

RecapDifficulty: Advanced1 min

Recap: REST and Resource-Oriented Design

Name the nouns, give each set and member a path, and let the method and query say the rest.

Resource design turns a domain into paths a client can guess.

  • REST is six constraints, each buying a property; stateless means no conversation memory, not no data.
  • A URI names a resource; a URL also says where it is, a URN only names it.
  • Collections and items, /orders and /orders/42, with the method as the verb.
  • Nest one level where a parent owns its children, and give independent things a top-level path.
  • Actions become a state change, a sub-resource, or a POST to an action path, never a DELETE that loses the record.
  • Query parameters filter, sort and search; the path only names the collection.
  • Level 2 of the Richardson model is the practical target; hypermedia is level 3.
The design questions, and the rule for each
QuestionRule
What is a resource?Anything the client needs to name, as a plural noun
How is one member reached?Its collection plus a stable, opaque id
How deep to nest?One level, for ownership
How to model an action?PATCH a state, POST a sub-resource, or POST to an action path
Where do filters go?The query string
Where does the verb go?The HTTP method