liveBook · Manning

Resource orientation

As explained in API Design Patterns

A resource-oriented API organizes an interface around named resources and a limited standardized set of operations that apply to those resources.

Resource orientation designs an API around named resources and a small, standardized set of operations. Instead of inventing an action for every behavior, designers combine familiar methods with resources such as FlightReservation, making interfaces easier to learn, understand, and remember. section 1.3 section 1.5

Prefer resource orientation when consistency and discoverability matter, but compare it with RPC-style designs:

  • Arbitrary RPC methods might use ScheduleFlight(), GetFlightDetails(), CancelReservation(), and RescheduleFlight(), forcing users to remember many names and resource distinctions. section 1.3
  • A resource-oriented design standardizes Create, Get, List, Delete, and Update across resources, producing methods such as CreateFlightReservation() and ListFlightReservations(). section 1.3
  • Do not treat resource orientation as universally superior: RPC-oriented APIs can fit some stateless scenarios, while standardized resources often improve usability elsewhere. section 1.3
Table 1.2 Summary of standard methods and their meanings (view table figure)

RPC

Description

Create<Resource>()

Creates a new <Resource>

Get<Resource>()

Shows information about a specific <Resource>

List<Resources>()

Shows a list of all existing <Resources>

Delete<Resource>()

Deletes an existing <Resource>

Update<Resource>()

Updates an existing <Resource> in place

Use the standard-method table to map Create, Get, List, Delete, and Update to their intended operations. section 1.3

Flight reservations

Model FlightReservation as the resource, then expose CreateFlightReservation(), GetFlightReservation(), ListFlightReservations(), DeleteFlightReservation(), and UpdateFlightReservation(). This replaces a scattered collection of flight- and reservation-specific actions with a predictable method pattern. section 1.3

How API Design Patterns covers it

How deep it goes
Defines resources and five standard methods, then contrasts their usability with arbitrary RPC naming.
Examples
Uses flight booking actions and a FlightReservation resource to demonstrate standardized method naming.
What you can do after
Apply a standard resource-and-method pattern when designing APIs, while recognizing when RPC-oriented designs fit better.
How it connects
Connects resources and standardized methods with RPC-style APIs, RPC-oriented APIs, and API usability.

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.