liveBook · Manning

Data transfer object

As explained in Secure APIs

A data transfer object is a data structure used to carry structured data between software layers or processes without encapsulating domain behavior.

A data transfer object (DTO) is a data structure that carries structured data between software layers or processes without carrying domain behavior. In API implementations, it limits each boundary to the data that layer needs, such as moving data between the API, business, and database layers. section 1.2.2

Use DTOs as part of secure data handling:

  • Transfer only the required fields between the API layer, business layer, database layer, and other layers. section 1.2.2
  • Validate and sanitize incoming and outgoing data regardless of its origin; DTOs support the pattern but do not replace validation. section 1.2.2 section 1.5
  • Combine DTOs with parameterized database queries to address data-handling risks such as SQL injection. section 1.2.2
  • Test every layer with unit, integration, and security-focused testing so the implementation behaves as intended. section 1.5
Figure 1.6 Security by design fits into every step of the API development cycle. It encourages us to approach design, implementation, testing, and operations from a security point of view.
figure

Use the security-by-design cycle to place DTO decisions alongside design, implementation, testing, and operations. section 1.5

How Secure APIs covers it

How deep it goes
Defines DTOs and their security purpose, but stops short of showing DTO code or a construction procedure.
Examples
Uses API, business, and database layers as the concrete transfer path, with incoming and outgoing payloads as validation boundaries.
What it assumes
Assumes basic awareness of API layers and payloads while emphasizing validation regardless of data origin.
What you can do after
Apply DTOs to restrict transferred fields, then validate payloads and test each application layer.
How it connects
Connects DTOs with API security, data validation, zero-trust security, serialization, and parameterized database queries.

Also explained in

Compare how 6 books explain data transfer object →

Related concepts

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