12 Singleton sub-resources

 

This chapter covers

  • What singleton sub-resources are
  • Why and when we should split data off into a singleton sub-resource
  • How standard methods interact with sub-resources
  • Where singleton sub-resources live in the resource hierarchy

In this pattern, we’ll explore a way of structuring related but independent data by moving it from a set of properties on a resource to a singleton child of that resource. This pattern handles scenarios where a specific collection of data might change independently of the parent, have different security requirements, or simply might be too large to store directly as part of the resource.

12.1 Motivation

12.1.1 Why should we use a singleton sub-resource?

12.2 Overview

12.3 Implementation

12.3.1 Standard methods

12.3.2 Resetting

12.3.3 Hierarchy

12.3.4 Final API definition

12.4 Trade-offs

12.4.1 Atomicity

12.4.2 Exactly one sub-resource

12.5 Exercises

Summary