<?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>kill the radio &#187; api</title>
	<atom:link href="http://blog.killtheradio.net/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.killtheradio.net</link>
	<description>or die trying</description>
	<lastBuildDate>Fri, 18 Jun 2010 04:56:10 +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>A simple (but long-winded) guide to REST web services</title>
		<link>http://blog.killtheradio.net/how-tos/a-simple-but-long-winded-guide-to-rest-web-services/</link>
		<comments>http://blog.killtheradio.net/how-tos/a-simple-but-long-winded-guide-to-rest-web-services/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 10:15:39 +0000</pubDate>
		<dc:creator>Andrew Lyon</dc:creator>
				<category><![CDATA[How to's]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://blog.killtheradio.net/?p=343</guid>
		<description><![CDATA[After all my research on what it means for a service to be RESTful, I think I&#8217;ve finally got a very good understanding. Once you understand a critical mass of information on the subject, something clicks and the first thing that comes in to your head is &#8220;Oh yeah! That makes sense!&#8221; It&#8217;s important to [...]]]></description>
			<content:encoded><![CDATA[<p>After all my research on what it means for a service to be RESTful, I think I&#8217;ve finally got a very good understanding. Once you understand a critical mass of information on the subject, something clicks and the first thing that comes in to your head is &#8220;Oh yeah! That makes sense!&#8221;</p>
<p>It&#8217;s important to think of a REST web service as a web site. How does a website work?</p>
<ul>
<li>A website works using HTTP. If you need to fetch something on a website, you use the HTTP verb &#8220;GET.&#8221; If you need to change something, you use &#8220;POST.&#8221; A RESTful web service uses other HTTP verbs as well, namely <a rel="nofollow" href="http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-the-story/" target="_blank">PUT</a> and DELETE, and can also implement OPTIONS to show which methods are appropriate for a resource.</li>
<li>A website has resources. A resource can be information, images, flash, etc. These resources can have different representations: HTML, a jpeg, an embedded video. REST is the same way. It is resource-centric. Want a list of users? GET /users. Want an event? GET /events/5. Want to edit that event? PUT /events/5. <em> </em><em>Every resource has a unique URL to identify it!</em></li>
<li>Resources are not dealt with directly. Instead, representations of resources are used. This can be a bit hard to grasp. What is a user? It&#8217;s a nebulous object somewhere that I cannot interact with. It is an idea, an entity. A representation is a form of the user resource I <em>can</em> interact with. A representation can be a comma delimited list, JSON, XML&#8230;anything the client and server both understand. How do we know what we&#8217;re interacting with? Media types:</li>
<li>As a website will tell you what kind of image you&#8217;re requesting, a REST service tells you what kind of resource representation you are receiving. This is done using media types. For instance, if I do a GET /events/7, the Content-Type may be &#8220;application/vnd.beeets.event+json&#8221; which tells us this is a vendor specific media (the &#8220;vnd&#8221;) and it&#8217;s an event in JSON format. You can pass these media types in your Accept headers to specify what type of representation you would like. These media types are documented somewhere so that client will know exactly what to expect when consuming them.</li>
<li>If you request a page that doesn&#8217;t exist or you aren&#8217;t authorized to view, a website will tell you. This is done using headers. A good REST service will utilize HTTP status headers to do the same. 200 Ok, 404 Not Found, 500 Internal Server Error, etc. These have already been defined and refined over many, many years by people who have been doing this a lot longer than you (probably)&#8230;use them.</li>
<li>A website will have links from one page to another. This is one of the main points of a REST service, and is also widely forgotten or misunderstood (it took me a while to figure it out even doing intense research). Resources in a REST service link to eachother, letting a client know what resources can be found where, and how they relate to eachother. An HTML page has links to it. So does a REST resource. Links can be structured however you like, but some good things to include are the URI of the linked resource, the relationship it has with the current resource, and the media type. This creates what&#8217;s known as a &#8220;loose coupling&#8221; between client and server. A client can crawl the server and figure out, only knowing a pre-defined set of media types, what resources are where and how to find them. This principal is known as HATEOAS (or &#8220;Hypermedia as the Engine of Application State&#8221;).</li>
<li>REST is stateless. This means that the server does not track any sort of client state. There are no session tokens the client uses to identify itself. There are no cookies set. Every request to the REST service <em>must</em> contain all information needed to make that request. Need to access a restricted resource? Send your authentication info for each request. It&#8217;s that simple. Isn&#8217;t it easier to track session? Not really. Maybe it&#8217;s easier on a small level, but once you start needing to scale, you will wish you&#8217;d gone stateless. Using a combination of HTTP basic authentication and API/Secret request signing, you don&#8217;t have to send over plain text passwords at all. Hell, even throw in a timestamp with each request to minimize replay attacks. You can get as crazy as you&#8217;d like with security. Or for those who prefer security over performance, use SSL.</li>
</ul>
<p>Now for some examples. Because I&#8217;m currently working on an event application, we&#8217;ll use that for most of the examples.</p>
<p>Let&#8217;s get a list of events from our server:</p>
<pre>GET /events
Host: api.beeets.com
Accept: application/vnd.beeets.events+json

{"page":1,"per_page":10}
-----------------------------------------
HTTP/1.1 200 OK
Date: Tue, 01 Dec 2009 04:12:48 GMT
Content-Length: 1430
Content-Type: application/vnd.beeets.events+json

{
	"total":81,
	"events":
	[
		{
			"links":
			[
				{
					"uri":"/events/6",
					"rel":"/rel/event self edit",
					"type":"application/vnd.beeets.event"
				},
				{
					"uri":"/locations/121",
					"rel":"/rel/location",
					"type":"application/vnd.beeets.location"
				}
			],
			"id":6,
			"title":"Paris Hilton naked onstage",
			...
		},
		...
	]
}</pre>
<p>What do we have? A list of events, with links to the resource representations of those events. Notice we also have links to another resource: the location. We can leave that for now, but let&#8217;s pull up an event:</p>
<pre>GET /events/6
Host: api.beeets.com
Accept: application/vnd.beeets.event+json

-----------------------------------------
HTTP/1.1 200 OK
Date: Tue, 01 Dec 2009 04:12:48 GMT
Content-Length: 666
Content-Type: application/vnd.beeets.event+json

{
	"links":
	[
		{
			"uri":"/events/6",
			"rel":"/rel/event self edit",
			"type":"application/vnd.beeets.event"
		},
		{
			"uri":"/locations/121",
			"rel":"/rel/location",
			"type":"application/vnd.beeets.location"
		}
	],
	"id":6,
	"title":"Paris Hilton naked onstage",
	"date":"2009-12-05T04:00:00Z"
}</pre>
<p>Using the link provided in the event listing, we managed to pull up an individual event, which we know how to parse because we know the media type&#8230;but wait, what&#8217;s this? OMG, someone is trying to smear Paris!! She&#8217;s on at 8:30!!! NOT 8!!! Let&#8217;s edit&#8230;if we do a PUT with new information, we&#8217;ll be able to save Paris&#8217; good name:</p>
<pre>PUT /events/6
Host: api.beeets.com
Accept: application/vnd.beeets.event+json
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

{"title":"Paris Hilton naked onstage (yuck)","date":"2009-12-05T04:30:00Z"}
-----------------------------------------
HTTP/1.1 200 OK
Date: Tue, 01 Dec 2009 04:12:48 GMT
Content-Length: 666
Content-Type: application/vnd.beeets.event+json

{
	"links":
	[
		{
			"uri":"/events/6",
			"rel":"/rel/event self edit",
			"type":"application/vnd.beeets.event"
		},
		{
			"uri":"/locations/121",
			"rel":"/rel/location",
			"type":"application/vnd.beeets.location"
		}
	],
	"id":6,
	"title":"Paris Hilton naked onstage (yuck)",
	"date":"2009-12-05T04:30:00Z"
}</pre>
<p>Holy shit, that was close. Notice we had to pass in authorization info, but now Paris won&#8217;t sue us for spreading misinformation. Phew.</p>
<p>What have we learned? Given one URL (/events), we have discovered two more (/locations/[id] and /events/[id]). We&#8217;ve also seen the media types in the responses that allow the client to know what kind of resource it&#8217;s dealing with and how to consume it.</p>
<p>Hopefully this pounds two really important points in: media types and HATEOAS. Without them, it&#8217;s not REST. You can&#8217;t just pass application/xml or application/json for every response. Sure, maybe the client can decode it, but they don&#8217;t know <em>what it is</em>, and without linking to other resources, they don&#8217;t know how to find anything&#8230;unless you want to document everything and <em>never change your service</em>.</p>
<p>Some other tips/points:</p>
<ul>
<li>Give yourself a few initial entry points to your REST service. You should be able to discover all of the resources in it just by crawling. If you can&#8217;t, you haven&#8217;t done HATEOAS correctly. This is a lot harder than it sounds, but it&#8217;s more than useful later on. Think of your REST service like a website with <span style="text-decoration: underline;">good</span> navigation.</li>
<li>Remember to implement the OPTIONS verb for your resources. It will tell the client what verbs can be used on what resources. With some decent routing built into your application, this should be a cakewalk.</li>
<li>As mentioned, you can use HTTP basic authentication for your requests. If the client is anything but a web browser, you won&#8217;t have to serve up an ugly popup login box, you can just do all that shit transparently. If you don&#8217;t want to send a cleartext password (please don&#8217;t!) you can salt the password on the client side and send it over. Hash the password again with the client&#8217;s secret for added security. Crackers will be amazed at your 1337 computer hacking skillz. You can then verify the hashed salted value on the server side. Add client-secret request signing with a timestamp for uber security.</li>
<li>Read a lot more info on REST. It seems that SO many &#8220;RESTful&#8221; services out there are half-baked and made by people who researched the topic for half a day. Some good ones to take points from are the <a href="http://kenai.com/projects/suncloudapis/pages/Home" target="_blank">Sun Cloud API</a> and the <a href="http://developer.netflix.com/docs/REST_API_Conventions" target="_blank">Netflix API</a>. Notice the documentation of media types and LACK of documentation on every single URL you can request. This is that loose-coupling stuff I was talking about.</li>
</ul>
<p>That&#8217;s it for now! I wrote this as a culmination of knowledge for the last week or so of research I&#8217;ve done&#8230;please let me know if any information is missing or incorrect and I can make updates. Hope it was helpful!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.killtheradio.net/how-tos/a-simple-but-long-winded-guide-to-rest-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Revisited: REST vs RPC</title>
		<link>http://blog.killtheradio.net/technology/revisited-rest-vs-rpc/</link>
		<comments>http://blog.killtheradio.net/technology/revisited-rest-vs-rpc/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 00:52:42 +0000</pubDate>
		<dc:creator>Andrew Lyon</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[rpc]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://blog.killtheradio.net/?p=321</guid>
		<description><![CDATA[This is a response to a previous post I made about how HTTP authentication is the reason why I&#8217;m not building a REST API. After doing a bit more research, I&#8217;ve decided that REST is many times better than RPC. Reviewing a lot more information on REST revealed that HTTP authentication is not at all [...]]]></description>
			<content:encoded><![CDATA[<p>This is a response to a <a href="http://blog.killtheradio.net/technology/rest-vs-rpc-and-why-authentication-is-the-deciding-factor/">previous post I made</a> about how HTTP authentication is the reason why I&#8217;m not building a REST API. After doing a bit more research, I&#8217;ve decided that REST is many times better than RPC. Reviewing a lot more information on REST revealed that HTTP authentication is not at all required&#8230;but instead a suggested method of authentication only because it&#8217;s already built. In fact, any authentication scheme could be cooked up and used. I&#8217;ve currently got my eye on OAuth.</p>
<p>That being said, our internal framework is now being updated to support routing different requests to different controllers/actions based on the request method. For instance, I can now route a &#8220;POST /events&#8221; to /events/add_event, or &#8220;GET /events&#8221; to /events/get_events. That just about seals the deal on RESTifying the framework, except that I&#8217;ll also have to come up with a scheme to implement status headers in the response, either automatically or semi-manually.</p>
<p>There will be no need to do a sort-of REST implementation on the www site. All information needed can be gathered through the API. Gnar, duude.</p>
<p>In conclusion, I&#8217;ve decided to go with REST after all. It&#8217;s a great architecture, and the best part is that it&#8217;s already built for me. Wicked.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.killtheradio.net/technology/revisited-rest-vs-rpc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REST vs RPC (and why authentication is the deciding factor)</title>
		<link>http://blog.killtheradio.net/technology/rest-vs-rpc-and-why-authentication-is-the-deciding-factor/</link>
		<comments>http://blog.killtheradio.net/technology/rest-vs-rpc-and-why-authentication-is-the-deciding-factor/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 00:15:20 +0000</pubDate>
		<dc:creator>Andrew Lyon</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[rpc]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://blog.killtheradio.net/?p=313</guid>
		<description><![CDATA[So I&#8217;ve been in the process of converting beeets.com, which is currently a &#8220;website&#8221; with integrated back-end code, to a front-end with a back-end API. It&#8217;s been an interesting journey, and has spawned a lot of thought recently about how to implement the API. Obviously, whenever someone says web API, REST is the first this [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been in the process of converting beeets.com, which is currently a &#8220;website&#8221; with integrated back-end code, to a front-end with a back-end API. It&#8217;s been an interesting journey, and has spawned a lot of thought recently about how to implement the API.</p>
<p>Obviously, whenever someone says web API, REST is the first this that comes to mind. &#8220;Let&#8217;s make it a REST API!&#8221; From what I&#8217;ve been reading about REST (I tend not to use terminology without knowing what the hell it means) many &#8220;REST&#8221; services aren&#8217;t very RESTful (<a rel="nofollow" href="http://tomayko.com/writings/rest-to-my-wife" target="_blank">&#8220;How I Explained REST to My Wife&#8221;</a> &#8211; great intro to REST). In fact, the way I&#8217;ve implemented the beeets API happens to be closer to RPC. After doing my fair share of research, I&#8217;m ok with this.</p>
<p>REST seems like an excellent architecture. In fact, one of the world&#8217;s largest global networks is built on that architecture. It works well for what it does&#8230;but what the hell does it do? From what I&#8217;ve been reading, it gives &#8220;resources&#8221; (pieces of information) a single location to be accessed/updated/created/deleted. At least this is how it works on the web.</p>
<p>RPC is basically a function or method that runs on a remote machine that can be called by a local machine, completely transparent to the local code. Most RPC implementations work on their own conventions, separately from the beautiful architecture which is REST&#8230;what is otherwise known as reinventing the wheel.</p>
<p>So why am I okay with using RPC in the beeets API? The main reason is that RESTful authentication is total junk. It&#8217;s great for server-server communication, but NOT so great for user interactions. Users are used to seeing pretty login boxes with &#8220;forgot your password? reset it, moron!&#8221; or &#8220;create an account!&#8221; links. Popping up an HTTP login screen is not cool. It&#8217;s <span style="text-decoration: underline;">not cool</span>. This is my main problem with REST.</p>
<p>That being said, if you cannot authenticate REST, then using the built-in methods POST, PUT, DELETE are more or less worthless, unless you have a <em>completely</em> public set of information that anybody can add to, change, or remove&#8230;in which case, REST would kick ass.</p>
<p>In light of REST lacking in this area, I think the following makes sense. Create an RPC API that authenticated servers can call to get/create/update/delete information. IPhones, Facebook apps, etc can use this RPC for interacting with the actual dataset. Then on the www front-end, create a REST system that only implements GET.</p>
<p>So I could go to beeets.com/events/123-native-american-slaughter-celebration and get an HTML page with links I can click, an awesome layout, etc. I could go to beeets.com/events/123-native-american-slaughter-celebration.json and get a JSON representation of that event, with URLs to other pages which could be JSON-encoded if need be.</p>
<p>In other words, create a read-only RESTful service on top of the www site, and use an RPC for create/update/delete interactions with the dataset. The already-public information is freely accessibly, without any sort of authentication, so any person or system that cares to consume it can do so. This way you&#8217;re still mapping a resource to a location, and providing multiple consumption formats for said resource.</p>
<p>If there is any other way to authenticate users against a RESTful system without an HTTP login, and while being able to control the actual login/registration flow and layout, PLEASE let me know!</p>
<p>UPDATE: <a href="http://blog.killtheradio.net/technology/revisited-rest-vs-rpc/">please read my followup</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.killtheradio.net/technology/rest-vs-rpc-and-why-authentication-is-the-deciding-factor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
