Summary
In this chapter, we explored how to leverage web APIs and create web services that expose REST endpoints to share data over HTTP. We also saw how to decouple the model from the "presentation" using DTOs.
DTOs are the equivalent of view models, but for web services. They are classes specially crafted around a specific resource: an HTTP endpoint. Instead of returning raw data to the client, a DTO can encapsulate the result of computations, limit the number of exposed properties, aggregate results, and flatten data structures to carefully craft the API contract representing the input and output of its endpoint.
Then we dug a little further along that path by defining that DTOs are part of the API contracts. A contract is the definition of our web APIs, so its consumers know how to communicate with it. We also looked at sharing DTOs between .NET projects.
In the end, we established that it is imperative to decouple the components from our systems, which follows...