4 Resource scope and hierarchy
This chapter covers...
- What is "resource layout"?
- The various types of resource relationships (reference, many-to-many, etc)
- How entity relationship diagrams describe resource layout
- How to choose the right relationship between resources
- Resource layout anti-patterns to be avoided
As we learned in Chapter 1 (Introduction to APIs), shifting our focus away from actions and towards resources allows us to more easily and more quickly build up our familiarity of an API by leveraging simple patterns. For example, REST provides a set of standard verbs which we can apply to a bunch of resources, meaning that for every resource we learn about, we also pick up 5 different actions that can be performed on that resource (Create, Get, List, Delete, and Update).
While this is valuable, it means that it becomes far more important to think carefully about the resources we define as part of an API. A key part of choosing the right resources is understanding how they'll fit together in the future. In this chapter, we'll explore how we might lay out the various resources in an API, the options available, and general guidelines for choosing the right way to associate resources with one another. Additionally, we'll look at a couple of anti-patterns (things not to do) when considering how to lay out a set of resources in an API. Let's start at the beginning by looking at what we mean specifically by "resource layout".