I'm curious to know how others have dealt with the issue of generating hypermedia links for their web APIs? Specifically, I'm using ASP.NET Web API, and am torn between having operations return hypermedia-related types, or returning the resource itself, and having the hypermedia stuff happen later in the pipeline. That is, do people tend to do things like:
public Resource<Order> GetOrder(int id) {
return new Resource<Order>() {
Content = new Order(),
Links = new LinkCollection<Order>() { new AddOrderLink(), new UpdateOrderLink()}
}
Or something more like
public Order GetOrder(int id) { return new Order(); }
And then add hypermedia links inside an HttpOperationHandler or custom formatter or something?
If the approach is more like #2, how do you know what links to generate? Just have some standard set of links that get generated for all Order objects? Attributes decorating various operations in OrdersController?
I prefer option two (adding the hypermedia links later in the pipeline) and blogged about doing this yesterday.
The solution was to "enrich" my resources with hypermedia links before they are returned to the client using a message handler.