liveBook · Manning

Full replacement

As explained in API Design Patterns

Full replacement is replacing an entire existing resource representation rather than changing only selected parts.

Full replacement updates an entire resource field or representation instead of changing selected items. It is necessary when list positions are unstable: an administrator added or removed from a repeated field can shift indexes, making an index-based update ambiguous. section 8.3.3

For dynamic maps, full replacement can remove a key by retrieving the resource, deleting the key, and replacing the whole map field. Freshness checks can protect consistency, but replacing an entire dynamic resource becomes more complicated. section 8.3.6

Replacing a repeated administrator list

A ChatRoom with an administrators list should receive the complete intended list when administrator data changes. Avoid PATCH requests that assign names to Index 0 or Index 1, because list order is not guaranteed. For dynamic settings, PATCH with an explicit field mask and an omitted value is preferred when removing only one key; full replacement is the broader fallback. section 8.3.3 section 8.3.6

Listing 8.5 Representation of a ChatRoom with multiple administrators
interface ChatRoom {
  id: string;
  title: string;
  description: string;
  administrators: User[];   #1
}
 
interface User {
  name: string;
  email: string;
  // ...
}

Inspect the ChatRoom representation to see the repeated administrators field that motivates full replacement. section 8.3.3

How API Design Patterns covers it

How deep it goes
Explains unstable indexes, retrieval and deletion, freshness checks, and the field-mask alternative without detailing storage implementation.
Examples
Demonstrates ChatRoom administrators, index-based PATCH updates, and removal of a settings key through an omitted field-mask value.
What it assumes
Assumes familiarity with API resources, repeated fields, field masks, JSON maps, and PATCH-style requests.
What you can do after
Apply it via API resource updates while avoiding ambiguous repeated-field indexes and recognizing when a field mask is safer.
How it connects
Connects full replacement with repeated fields, field masks, dynamic data structures, JSON, and freshness checks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.