<?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>bogdan@j3e &#187; Web API</title>
	<atom:link href="http://www.bserban.org/category/web_api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bserban.org</link>
	<description>Web, Java, J2EE, SaaS, Tips&#38;Tricks</description>
	<lastBuildDate>Thu, 08 Jul 2010 11:53:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>WEB API best practices</title>
		<link>http://www.bserban.org/2009/02/web-api-best-practices/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=web-api-best-practices</link>
		<comments>http://www.bserban.org/2009/02/web-api-best-practices/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 13:32:49 +0000</pubDate>
		<dc:creator>bserban</dc:creator>
				<category><![CDATA[SOA]]></category>
		<category><![CDATA[Web API]]></category>
		<category><![CDATA[SOA best practises]]></category>

		<guid isPermaLink="false">http://www.bserban.org/?p=113</guid>
		<description><![CDATA[Recently I had to do an API for my application. Coming from the world of J2EE, my first thought was to make a web service based on SOAP, but I soon realized that this type of J2EE web services is heavy. They are slow and cumbersome and requires the use of specialized frameworks or j2ee [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.bserban.org%2F2009%2F02%2Fweb-api-best-practices%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.bserban.org%2F2009%2F02%2Fweb-api-best-practices%2F&amp;source=bserban&amp;style=normal&amp;service=bit.ly&amp;hashtags=SOA,SOA+best+practises,Web+API" height="61" width="50" /><br />
			</a>
		</div>
<p>Recently I had to do an API for my application. Coming from the world of J2EE, my first thought was to make a web service based on SOAP, but I soon realized that this type of J2EE web services is heavy. They are slow and cumbersome and requires the use of specialized frameworks or j2ee containers that support such services. After a careful study of the problem I have concluded that the best solution would be using services REST like, based on XML and JSON.</p>
<p>Read more about REST services in Roy Thomas Fielding’s dissertation paper <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm">Representational State Transfer (REST)</a>. This will give you some insides about what REST should be.</p>
<p>Anyway, I don’t plan to write about REST, I just want to share you some of the best practices for developing an web API. When you design an API you should be aware that from the moment that it’s launched to the public, changing it will become impossible An API evolves over time, but because you already have customers, you need to be compatible with earlier versions, otherwise customers will leave</p>
<p>Some things to keep in mind.</p>
<ol>
<li>Create a subdomain for the API, it will help you a lot to load balance your traffic. You could also have an URL path, but still will have the same entry point as the main application. However, the best is to create a <strong>subdomain</strong> for API. </li>
<li>Version the API by including the version in the URL. This will help you stay compatible with earlier versions of the API, until everyone will upgrade to new version. Example:&#160;
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> api.mydomain.net/v1/my_api_name/my_entry_point</pre>
</p></div>
</p></div>
</li>
<li>You should split your API in packages by using the URL namespace, Example
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> api.mydomain.net/v1/<strong>namespace1</strong>/my_entry_point1</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> api.mydomain.net/v1/namespace2/my_entry_point2</pre>
</p></div>
</p></div>
</li>
<li>Create <strong>API keys</strong>. You need a way to see who is using your API and how. If you do not have such keys you&#8217;ll never know how many customers you have.This practice would allow the measurement of service usage by customers and to impose limits for use. </li>
<li><strong>Monitor</strong> everything. Use your access log to monitor use of services. You need to know how many accesses, errors, readings, queries, changes you have for each service. </li>
<li>Create <strong>API documentation with examples</strong>. Create applications for demo purposes. </li>
<li>Use <strong>GET for read</strong> and <strong>POST for change</strong>. If the changes do not require a large volume of data, transmit data via POST URL, in this way you can log them into access.log. This is useful for statistics. </li>
<li>You should use data collected in access logs to improve service or to create&#160; <strong>personalization and recommendation engines</strong> </li>
</ol>
<p>Keep an eye on this post, because I intend to update it regularly. Know other good practices? If yes, then leave a message. Thanks!</p>
<p><div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:85cf1878-94fa-41eb-a67c-ad64c5c6f1e7" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/web+API" rel="tag">web API</a>,<a href="http://technorati.com/tags/REST" rel="tag">REST</a>,<a href="http://technorati.com/tags/SOA" rel="tag">SOA</a>,<a href="http://technorati.com/tags/SOA+best+practises" rel="tag">SOA best practises</a></div>
</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.bserban.org%2F2009%2F02%2Fweb-api-best-practices%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.bserban.org%2F2009%2F02%2Fweb-api-best-practices%2F&amp;source=bserban&amp;style=normal&amp;service=bit.ly&amp;hashtags=SOA,SOA+best+practises,Web+API" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bserban.org/2009/02/web-api-best-practices/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
