This project is read-only.

Guidance On Links

Topics: Web Api
May 26, 2011 at 9:32 PM

I'm heavily leveraging hypermedia in my current work. As a result, nearly every response needs to carry with it some links. I've created some wrapper classes to handle collections and entities. I'm curious how others have handled this and if there are any opinions for or against this type of approach. Here is a brief sample of what my code looks like at present:

[WebGet(UriTemplate = "")]
public WebCollection<WebEntity<DesignSummary>> SearchDesigns(HttpRequestMessage request) { ... }

[WebInvoke(UriTemplate = "", Method = "POST")]
public HttpResponseMessage<WebEntity<Design>> PostDesign(Design design) { ... }

Where WebCollection<T> is something like this:

public class WebCollection<T> {
    public ObservableCollection<T> Items { get; set; }
    public Links Links { get; set; }

    public WebCollection() {
        Items = new ObservableCollection<T>();
        Links = new Links();

    public WebCollection(IEnumerable<T> items) {
        Items = new ObservableCollection<T>(items);
        Links = new Links();

    public Link Self {
        get { return Links.Find("self").FirstOrDefault(); }

    public Link Previous {
        get { return Links.Find("previous").FirstOrDefault(); }

    public Link Next {
        get { return Links.Find("next").FirstOrDefault(); }
WebEntity<T> is similar in nature. Basically, I wrap a core persistable object with some Links and possibly provide some helpers in order to improve the API. Any thoughts?