A data transfer object (DTO) models a message exchanged between an API client and a service. It serializes outbound data into the service’s expected format and deserializes inbound data into application-usable domain objects. A client may model only the message types or fields relevant to its responsibilities. section 8.1.7
Choose an implementation strategy by weighing development effort, correctness, type safety, and design-time coupling:
- Handwritten classes take more time but can reduce design-time coupling. section 8.4
- Code-generated classes are convenient, but can couple the client to the entire API. Binary payloads are almost always handled with generated DTOs. section 8.1.7 section 8.4
- Untyped maps or dictionaries are another option; service-provided libraries are also listed as an implementation strategy. section 8.1.7
Figure 8.3 An API client must have a data model of the messages that it exchanges with the service. The data model must serialize and deserialize correctly as defined by the schema. It can either be untyped (e.g. hash maps) or consist of handwritten or code-generated classes.
Shows how an API client’s message model can use untyped structures, handwritten classes, or generated classes, while conforming to the schema for serialization and deserialization. section 8.1.7









