Skip to content

csharp_short_samples

Bruno Oliveira edited this page Feb 8, 2011 · 1 revision

Typical hypermedia aware resource representation

A Restful application should support hypermedia content, and following this constraint, a typical resource representing an order to take part in some trainings could be:

<order>
    <product>rails training</product>				
      <price>512.45</price>
      <atom:link rel="refresh" href="http://www.caelum.com.br/orders/1" xmlns:atom="http://www.w3.org/2005/Atom"/>
      <atom:link rel="update" href="http://www.caelum.com.br/orders/1" xmlns:atom="http://www.w3.org/2005/Atom"/>
      <atom:link rel="pay" href="http://www.caelum.com.br/orders/1/payment" xmlns:atom="http://www.w3.org/2005/Atom"/>
      <atom:link rel="destroy" href="http://www.caelum.com.br/orders/1" xmlns:atom="http://www.w3.org/2005/Atom"/>
</order>

Short example

This documentation will guide you on how to create a simple REST client using Restfulie.

The client

If you use Restfulie to access such a resource, there will be one entry point and all it's interactions will be driven by hypermedia links:

//retrieves the resource through GET: the entry point
dynamic order = Restfulie.At(resourceURI).Get();

Console.WriteLine("the order price is " + order.Price);
Console.WriteLine("The order product is" + order.Product);

//  Executing a state transition:
order.Pay();	

// sends a delete request
order.Cancel()

The server

We will use the Restfulie's ordering example application in Rails as a server. Its source code is open and can be found at github, and a live version can be found at heroku.