This chapter covers
- Why we might want to update or retrieve only specific pieces of a resource
- How best to communicate the fields of interest to the API service
- How to handle individual items in complex fields, such as maps and interfaces
- Whether to support addressing individual items in a repeated field (e.g., arrays)
- Defining default values and handling implicit field masks
- How to deal with invalid field specifications
As we learned in chapter 7, it’s important that we have the ability to update resources in piecemeal fashion rather than always relying on full replacement. In this pattern, we explore using field masks as a tool to update only the specific fields we’re interested in for a given resource. Further, we also cover how to apply field masks to the same problem in the opposite direction: retrieving only specific fields on a resource. While slightly less common, the ability to retrieve parts of a resource rather than the entire thing is particularly important in memory-sensitive applications, such as IoT devices consuming API output.