liveBook · Manning

List

As explained in API Design Patterns

A list is an ordered collection of values that can be addressed by position and may contain nested lists or other data types.

A list is an ordered collection of values addressed by position with square brackets, such as items[2]. It may contain strings, numbers, maps, or nested lists, and commonly represents primitive values inherent to an API resource. section 5.6

Book categories

A Book resource can expose categories as a list of strings: categories: string[]. This keeps simple, intrinsic category data in the resource while presenting an interface useful to remote users, regardless of database storage. section 5.6

Design list fields with explicit ownership and limits:

  • Treat the entire list as one atomic value: replace it as a whole rather than exposing updates to individual positions. section 5.6.1
  • Provide one authoritative update path; separate endpoints for replacing a list and editing its items can create consistency surprises. section 5.6.1
  • Bound both the total item count and each item’s size, and reject inputs beyond those limits instead of truncating them. section 5.6.2
  • Use a subcollection when growth is difficult to bound; pagination can help manage an already large resource. section 5.6.2
  • Prefer an empty list as a genuine value, and avoid using it ambiguously to request a default. section 5.6.3
Listing 5.7 Storing a list of categories on a Book resource
interface Book {
  id: string;
  title: string;
  categories: string[];    #1
}

Shows a concise resource shape for storing a list of category strings on a Book. section 5.6

When an empty list cannot be distinguished from a default request, use a creation-time default only when empty is invalid; otherwise model the data as a separately managed subcollection. section 5.6.3

How API Design Patterns covers it

How deep it goes
Explains addressing, atomic replacement, consistency risks, bounds, defaults, and when to choose subcollections.
Examples
Uses a Book resource with a categories string list and contrasts inline lists with separately managed category resources.
What it assumes
Assumes basic data types and API resource modeling while establishing list behavior from indexing through validation.
What you can do after
Evaluate whether an API field should be an atomic bounded list, a defaulted value, or a paginated subcollection.
How it connects
Connects lists with API resources, JSON serialization, subcollections, pagination, relational storage, and ETags.

Also explained in

Compare how 21 books explain list →

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.