-
Notifications
You must be signed in to change notification settings - Fork 152
REST Resources Compositions and aggregations
One point worth keeping in mind while designing REST APIs is that you are not supposed to create a 1:1 mapping with your relational data model! REST resources are just REST resources, not database tables.!
When a use case requires that you compose/aggregate data coming from different places (e.g., multiple database tables, files, ...), then you have two basic choices.
You MAY let your API clients deal with the orchestration (i.e., let them interrogate n places to retrieve the necessary data and filter/sort/etc themselves). You SHOULD NOT do this in most cases.
The better alternative is to create REST resources that represent the aggregations/compositions that you require. For example, if you have a users resource and a loans resource, then nothing prevents you from creating a resource that exposes combinations of those in any way shape for form that fits your needs.
When you create compositions or aggregations, the semantics are up to you and depend on what you are trying to achieve. For example, you could decide that end users cannot send updates to a specific composed resource and return a 4xx code.
Or, to take another example, imagine that you create a composition between a loans resource and a users resource, you could let your API clients send updates of either the users, the loans, or both.
This project is distributed under the terms of the EUPL FOSS license
REST Resources Design Workflow
REST Resources Single items and collections
REST Resources Many to many Relations
REST Resources Relations expansion
HTTP Status Codes Success (2xx)
HTTP Status Codes Redirection (3xx)
HTTP Status Codes Client Error (4xx)
HTTP Status Codes Server Error (5xx)
Pagination Out of range/bounds
Long-running Operations Example
Concurrency vs Delete operation
Caching and conditional requests About
Caching and conditional requests Rules
Caching and conditional requests HTTP headers
Error handling Example with a single error
Error handling Example with multiple errors
Error handling Example with parameters
Error handling Example with additional metadata
Bulk operations HTTP status codes
Bulk operations Resources naming convention
Bulk operations Creation example
Bulk operations Update example
Bulk operations Create and update example
File upload Simple file upload
File upload Simple file upload example
File upload Complex file upload
File upload Complex file upload example
REST Security General recommendations
REST Security Insecure direct object references