<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mauricio Aniche &#187; REST</title>
	<atom:link href="http://www.aniche.com.br/tag/rest/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aniche.com.br</link>
	<description>Pensamentos sobre desenvolvimento de software</description>
	<lastBuildDate>Mon, 17 Oct 2011 00:59:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Restfulie 0.5.0 has been released!</title>
		<link>http://www.aniche.com.br/2010/07/restfulie-0-5-0-has-been-released/</link>
		<comments>http://www.aniche.com.br/2010/07/restfulie-0-5-0-has-been-released/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 15:03:21 +0000</pubDate>
		<dc:creator>mauricioaniche</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[restfulie]]></category>
		<category><![CDATA[asp.net mvc 2]]></category>

		<guid isPermaLink="false">http://www.aniche.com.br/?p=178</guid>
		<description><![CDATA[Mauricio Aniche with contributions from Pedro Reys and Felipe Seixas have released the Restfulie&#8217;s C# Server 0.5  support on top of Asp.Net Mvc 2. As new versions of Restfulie come up, it becomes more clear which extension points are important and should be easy to be used, the media type and http results are two <a href='http://www.aniche.com.br/2010/07/restfulie-0-5-0-has-been-released/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.twitter.com/mauricioaniche">Mauricio Aniche</a> with contributions from <a href="http://www.twitter.com/pedroreys">Pedro Reys</a> and <a href="http://www.twitter.com/seixasfelipe">Felipe Seixas</a> have released the Restfulie&#8217;s C# Server 0.5  support on top of Asp.Net Mvc 2.</p>
<p>As new versions of Restfulie come up, it becomes more clear which extension points are important and should be easy to be used, the media type and http results are two of those aspects that Restfulie C# tries to help the developers by allowing them to write classes focused on one task only as we shall see here.</p>
<p>A simple C# Item model can be rendered in your controller as in ruby and java:</p>
<pre class="csharp">[ActAsRestfulie]
public class ItemsController : Controller
{
private MemoryDatabase database;

public ItemsController()
{
  database = new MemoryDatabase();
}

public virtual ActionResult Index()
{
  return new Ok(database.List());
}

public virtual ActionResult Get(int id)
{
  var item = database.List().Where(i =&gt; i.Id == id).SingleOrDefault();
  if (item == null) return new NotFound();
  return new OK(item);
}
}
</pre>
<p>If you want to add some link relations to any resource, simply let your model implement IBehaveAsResource and add the SetRelations method:</p>
<pre class="csharp">public class Item : IBehaveAsResource
{
public void SetRelations(Relations relations)
{
  relations.Named("self").Uses().Get(Id);
  relations.Named("origin").At("http://www.some-fabric.com/");
}
}
</pre>
<p>The http GET request to an item with application/json in the accept header will now return:</p>
<pre class="javascript">{"Id":1,"Name":"Pencil","Price":"1.50",
"links":[{"rel":"self","href":"http://localhost:1198/Items/1"},
{"rel":"origin","href":"http://www.some-fabric.com/"}]}
</pre>
<p>But we know relations work in different ways with different media types (and the Link header) so you might want to add your own media type marshaller/unmarshaller, which is capable of understanding a new media type. Restfulie C# comes with support for application/json, application/xml and application/atom+xml.</p>
<p>If you want to add your own result, simply implement a RestfulieResult using a series of decorators to your new result:</p>
<pre class="csharp">public class OK : RestfulieResult
{
public OK() { }
public OK(object model) : base(model) { }

public override ResultDecorator GetDecorators()
{
  return new StatusCode((int)HttpStatusCode.OK,
    new ContentType(MediaType.Synonyms.First(),
    new Content(BuildContent())));
}
}
</pre>
<p>This <a href="http://wiki.github.com/mauricioaniche/restfulie.net/">release documentation is already out</a> and the <a href="http://github.com/mauricioaniche/restfulie.net/downloads">download</a> can also be done at github.</p>
<p>Restfulie C# requires the dot net framework 3.5+, and uses castle in order to create dynamic proxy for setting up relations.﻿</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.aniche.com.br%2F2010%2F07%2Frestfulie-0-5-0-has-been-released%2F&amp;title=Restfulie%200.5.0%20has%20been%20released%21" id="wpa2a_2"><img src="http://www.aniche.com.br/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.aniche.com.br/2010/07/restfulie-0-5-0-has-been-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

