Skip to content
mauricioaniche edited this page Sep 14, 2010 · 5 revisions

Basics

You can add hypermedia to any of your resources. To do that you just have to implement the interface IBehaveAsResource. The most simple implementation would be the following:

public void SetRelations(Relations relations)
{
}

It actually returns no relations.

Relation to a Action

You might want to add a relation to some action. The following code does that:

public void SetRelations(Relations relations)
{
    relations.Named("pay").Uses<SomeController>().SomeSimpleAction();
}

The code above creates a transition called “pay” and sets it to an action called “SomeSimpleAction”.

Your URL may have some parameters, just like an ID. You can pass it at the moment you are creating the transition. The following code does that:

public void SetRelations(Relations relations)
{
    relations.Named("get").Uses<SomeController>().Get(this.Id);
}

This code will actually get the Id and pass it to the Asp.NET MVC Url Generator. If its related route contains this parameter, it will include it in the Url.

Relation to an External Link

You can point a transition to an external link.

public void SetRelations(Relations relations)
{
    relations.Named("about").At("restfulie.caelumobjects.com");
}
Clone this wiki locally