I am evaluating how to add hypermedia links to DTO responses. Although there is no standard, add List to the response DTOs seems to be the suggested approach.
Do you know of any example or reference of implementation using ServiceStack framework?
Adding List is ok for me, but my doubts are about where to put the logic of the following links (Within the service or a specialized class that holds the state machine?) and where to resolve the routes (A filter?)
Thanks.
[Update] From ServiceStack version v3.9.62 it is posible to access Routes configuration via EndpointHost.Config.Metadata.Routes.RestPath, so the solution provided by tgmdbm can be improved withouth the need of "IReturn + Routes attributes", just using Metadata.Routes information. In fact all service metadata can be queried and used to cross-cutting concerns. Servicestack rocks.
The way I do this currently is I pass back a response dto which implements an interface
Then I use a response filter to generate the urls and populate the response headers with the links.
This seems the cleanest way. The
Link
object above effectively says "If you make this request with this method you will get back the named resource". The only HTTP thing that bleeds up to the BLL isMethod
. But you could get rid of that and only pass back GET urls. Or map it to some generalised "operation"?As an example:
(The
AddPage
method returns a clone of the request and sets the Page property appropriately.)Hope that helps.