Resource-Oriented Design
What is a REST API?
Section titled “What is a REST API?”A REST API is modeled as collections of individually-addressable resources:
- Resources are the nouns of the API (e.g., books, channels, players)
- Resources are referenced with their resource names (URIs)
- Resources are manipulated via a small set of methods (HTTP verbs)
The standard HTTP methods for REST APIs are: GET, POST, PUT, PATCH, and DELETE.
Resource Design Workflow
Section titled “Resource Design Workflow”When designing a REST API, follow this systematic workflow:
- Determine resource types: Identify what types of resources your API provides
- Determine relationships: Define how resources relate to each other
- Decide naming schemes: Establish resource name conventions based on types and relationships
- Decide resource schemas: Define resource representations (JSON structure)
- Assign methods: Map HTTP methods to each resource
What is a Resource?
Section titled “What is a Resource?”A resource is any piece of data or functionality that clients need to interact with. Resources are the fundamental building blocks of a RESTful API.
Resource Hierarchy
Section titled “Resource Hierarchy”A resource-oriented API is modeled as a resource hierarchy (a tree-like structure). Each node is either:
| Node Type | Description | Example |
|---|---|---|
| Singleton Resource | A single, specific instance (leaf node) | /books/1, /users/123/profile |
| Collection Resource | A group of resources of the same type (branch node) | /books, /users/123/orders |
Types of Resources
Section titled “Types of Resources”1. Singleton (Simple) Resource
Section titled “1. Singleton (Simple) Resource”A singleton resource represents a single, specific instance of something.
GET /api/books/1 # A specific bookGET /api/users/123 # A specific userGET /api/users/123/profile # User's profile (one-to-one)Characteristics:
- Represents one specific thing
- Has a unique identifier
- Contains detailed information about that item
- May have its own sub-resources
2. Collection Resource
Section titled “2. Collection Resource”A collection resource contains a list of resources (items) of the same type.
GET /api/books # All booksGET /api/users # All usersGET /api/orders # All ordersCharacteristics:
- Contains multiple resources of the same type
- Returns a list or array of items
- Supports create operations (POST)
- Can be paged, sorted, and filtered
3. Sub-Collection Resource
Section titled “3. Sub-Collection Resource”A sub-collection is a collection that belongs to a parent resource.
GET /api/books/1/authors # All authors of book 1GET /api/users/123/orders # All orders by user 123GET /api/projects/5/tasks # All tasks in project 5Characteristics:
- Express relationships between resources
- Show ownership or containment
- Provide scoped access to related data
Each sub-resource can be either:
- An instance resource (leaf):
/books/1/authors/3 - A collection resource (branch):
/books/1/authors
Resource Model
Section titled “Resource Model”A resource model defines what resources your API exposes, what actions can be performed on them, and how they relate to each other. Think of it as translating your application’s data (like database tables or domain objects) into the resources and URLs that clients will interact with.
The diagram below illustrates the aforementioned concepts of in a RESTful API.

Resource Relationships
Section titled “Resource Relationships”Resources model objects from the application data model and almost always have relationships to other resources. These relationships are often modeled using sub-resources.
Relationship Types
Section titled “Relationship Types”| Relation Type | Resources | Meaning |
|---|---|---|
| Independent | /projects, /tasks | Tasks can exist with or without a project |
| Dependent | /projects, /projects/{id}/tasks | Tasks must belong to a project instance |
| Associative | /users, /projects/{id}/collaborators | Users assigned to a project become collaborators |
Use Sub-Resources When:
Section titled “Use Sub-Resources When:”| Condition | Example |
|---|---|
| Child depends on parent | Mission crew depends on mission |
| Child belongs to parent | Moons belong to a planet |
| Child lifecycle tied to parent | Order items tied to order |
GET /api/missions/apollo-11/crew # Crew exists within mission contextPOST /api/planets/jupiter/moons # Add moon to JupiterUse References When:
Section titled “Use References When:”| Condition | Example |
|---|---|
| Resources exist independently | Astronauts exist without missions |
| Many-to-many relationships | Astronauts on multiple missions |
| Relationships change frequently | Spacecraft reassignments |
GET /api/astronauts/neil-armstrong{ "id": "neil-armstrong", "name": "Neil Armstrong", "current_mission": "apollo-11", "_links": { "self": "/api/astronauts/neil-armstrong", "current_mission": "/api/missions/apollo-11", "all_missions": "/api/astronauts/neil-armstrong/missions" }}Sub-Resource URI Patterns
Section titled “Sub-Resource URI Patterns”GET /{resource}/{resource-id}/{sub-resource}GET /{resource}/{resource-id}/{sub-resource}/{sub-resource-id}POST /{resource}/{resource-id}/{sub-resource}Examples:
# Get all authors of a specific bookGET /api/books/1/authors
# Get a specific author of a specific bookGET /api/books/1/authors/3
# Add an author to a bookPOST /api/books/1/authorsOperations on Collections
Section titled “Operations on Collections”Collection resources support various operations to manage and retrieve data efficiently.
Standard Operations
Section titled “Standard Operations”| Operation | HTTP Method | URI Pattern | Description |
|---|---|---|---|
| List all | GET | /resources | Retrieve all items in collection |
| Create | POST | /resources | Add a new item to collection |
| Get one | GET | /resources/{id} | Retrieve a specific item |
| Update | PUT | /resources/{id} | Replace an entire item |
| Partial update | PATCH | /resources/{id} | Modify specific fields |
| Delete | DELETE | /resources/{id} | Remove an item |
Collection Capabilities
Section titled “Collection Capabilities”Collections can be:
- Paginated: Return results in manageable chunks
- Sorted: Order results by specific fields
- Filtered: Return only items matching criteria
# Paginated requestGET /api/books?page=2&limit=20
# Sorted requestGET /api/books?sort=title:asc
# Filtered requestGET /api/books?filter=genre:fiction
# CombinedGET /api/books?page=1&limit=10&sort=published_date:desc&filter=author:TolkienFor detailed implementation guidance, see:
Quick Decision Guide
Section titled “Quick Decision Guide”When to Use Each Resource Type
Section titled “When to Use Each Resource Type”| Scenario | Resource Type | Example |
|---|---|---|
| Single configuration/settings | Singleton | /users/123/profile |
| List of similar items | Collection | /products |
| Items belonging to a parent | Sub-collection | /orders/5/items |
| One-to-one relationship | Singleton sub-resource | /planets/earth/atmosphere |
| One-to-many relationship | Sub-collection | /users/123/posts |
Common Resource Design Patterns
Section titled “Common Resource Design Patterns”1. Hierarchical Resources
Section titled “1. Hierarchical Resources”Use hierarchical (sub-resources) when:
- Clear ownership/containment relationship exists
- Child cannot exist without parent
- You need scoped access to related data
/projects/123/tasks/456 # Task 456 belongs to project 1232. Flat Resources with References
Section titled “2. Flat Resources with References”Use flat resources when:
- Resources can exist independently
- Resources are shared across multiple parents
- Deep nesting would become unwieldy
/tasks/456 # Task exists independently# Response includes: { "project_id": 123, ... }Hierarchy Depth Guideline
Section titled “Hierarchy Depth Guideline”Keep URI hierarchies shallow (2-3 levels maximum):
# Good - clear and manageable/universities/123/departments/456
# Avoid - too deep/universities/123/departments/456/courses/789/students/101/gradesSummary
Section titled “Summary”For detailed coverage of HTTP methods, see HTTP Verbs. For status codes, see HTTP Status Codes.
Resource-oriented design focuses on:
- Identifying resources (nouns) rather than actions
- Organizing resources in a logical hierarchy
- Using standard HTTP methods for operations
- Following consistent naming conventions
This approach creates APIs that are:
- Intuitive: Easy to understand and use
- Consistent: Predictable behavior across endpoints
- Scalable: Easy to extend with new resources
- Cacheable: Leverages HTTP caching mechanisms