liveBook · Manning

Type field

As explained in API Design Patterns

A type field is a resource field that identifies which subtype or representation applies to a polymorphic resource instance.

A type field identifies which subtype or representation applies to a polymorphic resource instance. Use a validated string rather than an enumeration, so clients can filter and create resources through the same field. section 16.3.2

Message filtering and creation

A Message resource can expose type values such as text, photo, audio, and video. ListMessages() can filter for type = photo, while CreateMessage() accepts the appropriate shape and type value. section 16.3.2

Treat the field as a stable discriminator:

  • Validate string values against the supported subtype set. section 16.3.2
  • Avoid changing an existing resource from one type to another; relationships may rely on its original shape. section 16.3.2

How API Design Patterns covers it

How deep it goes
Defines string validation, filtering, creation, and mutation risks, but defers subtype content storage.
Examples
Demonstrates Message values for text, photo, audio, and video in a typed interface.
What it assumes
Assumes polymorphic resources and generic interfaces, while teaching how to select and govern their discriminator field.
What you can do after
Apply it via validated string values, subtype filters, and stable resource representations.
How it connects
Connects polymorphism with validation, enumerations, resource filtering, creation, and resource relationships.

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.