This is an introduction to core five classes required to constructing a representation from the controller, this case the root of the API because it is the simplest. This pattern is the mainstay that variation emanate from and the files tend to live across two projects. The tutorial provides various views:
Note: this code assumes that the MVC pipeline is already setup
Below, you see on overview of the code, then you see the implementation, finally we’ll draw it again in a way to help you start to remember it! Remember, this is essentially the pattern of code you’ll use all the time with adding representations to the domain. No more, no less.
For the more visual, below is a diagram that layers between the Representation and the Model where:
Representation
s are serialised in and out across the request and response, respectivelyFromRepresentation
is an incoming representation mapped to a domain model (that may be validated and persisted, ie apply business process/rules)ToRepresentation
is an outgoing representation constructed from a domain with link relations created through a UriFactory
that maps resource identities to routes (ie back into the controller actions)Model
itself are the in-memory domain objects from persistenceNote: each of the boundaries denoted by box lines indicate potential impedance mismatch that should be understandable in the code
This diagram is generalisable to most MVC frameworks and suggest that perhaps we might need to find variations of the pattern to meet hypermedia designed APIs
Below is a way to understand the interaction of the pattern of representation request/response:
Note: if running the todo API itself, more links will be returned.