<?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>Our Geek Space &#187; rest api architecture</title>
	<atom:link href="http://blog.moove-it.com/tag/rest-api-architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.moove-it.com</link>
	<description>be free to express yourself...</description>
	<lastBuildDate>Thu, 26 Jan 2012 19:30:14 +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>Designing a RESTful API specification (part II)</title>
		<link>http://blog.moove-it.com/designing-a-restful-api-specification-part-ii/</link>
		<comments>http://blog.moove-it.com/designing-a-restful-api-specification-part-ii/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 18:02:12 +0000</pubDate>
		<dc:creator>Gian Zas</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[rest api architecture]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=76</guid>
		<description><![CDATA[- Every resource is identified by an URI The URI &#60;base_uri&#62;/car/&#60;car_id&#62; identifies the car whose ID is &#60;car_id&#62;. If you are designing an API to interact with a software system, the ID probably will be the primary key of the car in the database - Use the HTTP Verbs. GET &#60;base_uri&#62;/car/&#60;car_id&#62; -&#62; This operation retrieves [...]]]></description>
			<content:encoded><![CDATA[<p>- <strong>Every resource is identified by an URI</strong></p>
<p>The URI &lt;base_uri&gt;/car/&lt;car_id&gt; identifies the car whose ID is &lt;car_id&gt;. If you are designing an API to interact with a software system, the ID probably will be the primary key of the car in the database</p>
<p>- <strong>Use the HTTP Verbs.</strong></p>
<p><em>GET &lt;base_uri&gt;/car/&lt;car_id&gt;</em> -&gt; This operation retrieves information about the car whose id is car_id. No side effects here, please!<br />
<em> GET &lt;base_uri&gt;/cars</em> -&gt; Retrieves the set of cars, parameters containing the page_size and page_number are highly recommended. No side effects.<br />
<em> POST &lt;base_uri&gt;/car </em>-&gt; Create a new car, the car attributes are passed as HTTP parameters. This operation must retrieve the ID of the new object created.<br />
<em> PUT &lt;base_uri&gt;/car/&lt;car_id&gt; </em>-&gt; Modify the data associated with the car, the attributes are passed as HTTP parameters<br />
<em> DELETE &lt;base_uri&gt;/car/&lt;car_id&gt; </em>-&gt; You want to delete an object? Just it!</p>
<p>Don&#8217;t use action names, like get_car, or browse_for_id in the URI, the verbs indicate the desired action</p>
<p>A principle-design discussion&#8230; singular or plural nouns at the URI? Personally I prefer nouns in singular for operations involving ONE resource, and plural for MORE than one resource.</p>
<p>- <strong>Use of HTTP Status codes</strong><br />
Use it to indicate the result of the operation.</p>
<p>I recommend that the API return appropriate HTTP status codes for each request.<em></em></p>
<p><em>200 OK:</em> The request has been successfully completed.<br />
<em> 304 Not Modified: </em>Operation ok. There was no new data to return<br />
<em> 400 Bad Request: </em>The request is invalid. Error messages are returned for explanation purposes.<br />
<em> 401 Not Authorized: </em>The credentials provided are invalid or are needed for the operation.<br />
<em> 403 Forbidden: </em>The request is refused by the API implementation. Error messages are returned.<br />
<em> 404 Not Found: </em>The resource requested doesn’t exist. Ex: The provided car_id in the url doesn’t exist.<br />
<em> 500 Internal Server Error: </em>An unrecoverable error has occurred at server side.</p>
<p><em> 502 Bad Gateway:</em> The API service is down or being upgraded<em></em></p>
<p><em>503 Service Unavailable: </em>The service is overloaded with a lot requests and can’t manage the incoming request.</p>
<p>- <strong>Error Messages</strong></p>
<p>When the API returns error messages it must comply with a structure. Here I present a simple structure in JSON format:</p>
<pre>{
    error_messages: [
        "error_message_1",
        "error_message_2",
        ...,
        "error_message_n"
    ]
}</pre>
<p>- <strong>Data Format</strong></p>
<p>The operations return information about the resource requested or information about error messages. The format of that information could be preferably at the moment JSON or XML.<br />
If you will be supporting more than one format, or think that in future you&#8217;ll be, a possible manner is to include the format at the URI, for example:<br />
<em> PUT &lt;base_uri&gt;/car.json/&lt;car_id&gt;<br />
PUT &lt;base_uri&gt;/car.xml/&lt;car_id&gt;</em></p>
<p><strong>Conclusion: </strong>The key base-aspects of designing a RESTful API are<br />
- Identify every resource (or object in OOP idiom) with an URI<br />
- Use HTTP verbs<br />
- Use HTTP status code<br />
- Don&#8217;t use action names in the URI</p>
<p>An important implementation detail: Use UTF-8, unless your data is only on languages with high code points (digging more in the cloud about this topic is recommended)</p>
<p>Another important aspect is about security access to the operation, but is an subject for a future post, stay tuned!</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/designing-a-restful-api-specification-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designing a RESTful API specification (part I)</title>
		<link>http://blog.moove-it.com/designing-a-restful-api-specification-part-i/</link>
		<comments>http://blog.moove-it.com/designing-a-restful-api-specification-part-i/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 18:00:15 +0000</pubDate>
		<dc:creator>Gian Zas</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[rest api architecture]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=74</guid>
		<description><![CDATA[When your business is about pushing and pulling data from an external system, or exposing your application domain to external clients, you often have two options: SOAP Webservices or a RESTful service. If you&#8217;re here there are great chances that you are ridding this new hype-age of web2.0 startups as if it was a new [...]]]></description>
			<content:encoded><![CDATA[<p>When your business is about pushing and pulling data from an external system, or exposing your application domain to external clients, you often have two options: SOAP Webservices or a RESTful service. If you&#8217;re here there are great chances that you are ridding this new hype-age of web2.0 startups as if it was a new religion (just like us). But these preferences are not enough to achieve a successful job done, you must learn new concepts and &#8220;stay in the zone&#8221;.</p>
<p>Ok, so you need to design a RESTful API (and implement it later?), you must be asking &#8220;first what the hell is REST?&#8221; &#8220;Why you write RESTful?&#8221; &#8220;Or is it a mistake?&#8221;. Here we go. If you feel comfortable with the basic concepts please jump to the second part.</p>
<p><strong>What is REST?</strong></p>
<p>REST (REpresentational State Transfer) is a style or a set of principles for software architecture for distributed systems, nothing else, is not a specification neither a standard and neither an implementation.</p>
<p>Actually REST has a niche in applications over HTTP, but technically this is not a barrier.<br />
- HTTP is a stateless protocol<br />
- It defines a set of operations: POST, GET, PUT, DELETE<br />
- Every resource has an universal address, the URI<br />
- Hypermedia documents for modeling the information of a resource</p>
<p><strong>What is a Resource?</strong></p>
<p>A resource is nothing else than the objects that you expose, like an invoice, a paycheck or a blog entry.</p>
<p><strong>HTTP Verbs:</strong></p>
<p><strong></strong><br />
The POST, GET, PUT and DELETE verbs map with the basic CRUD operations<br />
POST -&gt; Create<br />
GET -&gt; Read<br />
PUT -&gt; Update<br />
DELETE -&gt; Delete</p>
<p><strong>REST Operations</strong></p>
<p><strong></strong><br />
A REST operation consists of:<br />
- an URI identifying the resource<br />
- a set of additional parameters<br />
- a HTTP verb<br />
- the response status code<br />
- the information retrieved by the operation</p>
<p>continues&#8230;</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/designing-a-restful-api-specification-part-i/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

