Hi guys,
I have a very first draft of restfulie server for
asp.net mvc 2. I want some opinions:
The model needs to implement an IBehaveAsResource interface which has a method to define its transitions.
public class Order : IBehaveAsResource
{
public DateTime Date { get; set; }
public double Amount { get; set; }
public void SetTransitions(Transitions transitions)
{
transitions.Named("pay").Uses<OrdersController>().Index();
}
}
The controller needs to have the attribute [ActAsRestfulie]. In the action, it should return a RestfulieResult like Success (which returns http 200 and the resource). You can also send a different result if you want (for example, return new BadRequest()).
[ActAsRestfulie]
public class OrdersController : Controller
{
public virtual ActionResult Index()
{
var order = new Order {Amount = 333.44, Date = DateTime.Now};
return new Success(order);
}
}
The content negotiation is working. It is still pretty simple as it only accepts "application/xml". However, if a non-supported media type is provided, restfulie sends a Not Acceptable (406) automatically.
I tried to keep the
asp.net mvc development mindset. I guess it is pretty easy to use.
I am about to start the next ticket on lighthouse that is atom support. Any suggestions before that?
Regards,
Mauricio