Chapter 10: Design Patterns
Once you understand the basics of collection resources and object resources, we can look at the key URL design patterns. Don’t forget to read the Antipatterns section as well, where you’ll find similar examples showing incorrect usage.
Nested Resource
Let’s start with a pattern that, in my opinion, is often overused. Creating a nested resource only makes sense in cases where the parent resource contains a collection whose identifier is not unique across the entire system.
/orders/20220203001/addresses/delivery
/orders/20220203001/addresses/billing
/articles/39047664/revisions/1
/articles/39047664/revisions/2
The example above assumes that an order has two types of addresses: shipping and billing. The identifiers delivery
and billing
are not unique on their own within the entire REST API, but when combined with the order number, they are. The same applies to revisions
.