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 signature of the method is the following:

void SetRelations(Relations relations)

Obs: You SHOULD make the method virtual.

Relation to a Action

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

public virtual 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 virtual 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 virtual void SetRelations(Relations relations)
{
    relations.Named("about").At("restfulie.caelumobjects.com");
}
Clone this wiki locally