Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 5
REST APIs generally format the responses in JSON or XML. Both formats are well supported, with libraries available in most any modern programming language. Using one of these libraries, you'll find it relatively straightforward to convert the response into an object that you can manipulate in your application.
A REST example
Twitter has a great API to use for testing. Because some of Twitter's resources don't require authentication, you can see them right in the browser.
As an example, click on the following link: http://search.twitter.com/search.json?q=synedra&count=1
The response you see in your browser is the JSON representation of the search for "synedra" in the Twitter Search API. Using the JSON library for your programming language of choice, you can convert this response into a usable object. For instance, in Python you could do the following:
import urllib2
import simplejson
response =
urllib2.urlopen('http://search.twitter.com/search.json?q=synedra')
jsonobj = simplejson.load(response)
print jsonobj['results']
As you can see, the information contained in the Twitter response has been loaded up as an object (jsonobj).
Troubleshooting
One of the best troubleshooting strategies is avoiding problems in the first place. When developing against REST APIs, you
usually want to go with supported, tested libraries and follow sample code wherever possible. As in any other situation where
your application relies on a service you don't control, you need to code defensively. The structure of the response could
change, or the call could simply fail due to network or server issues. Your code needs to handle these unexpected issues gracefully.
You can save yourself a lot of trouble by logging the responses you get locally. Most servers don't log the responses they
send, so you may need that local log to figure out what happened when something goes wrong. And asking for support will be
much easier if you can send along an example of the failing response.
Successful requests. Sometimes when you encounter failures, it can feel like the server has a vendetta against you. But take heart, the server simply isn't smart enough to recognize your request and behave differently. Most likely your request has some minor issue that prevents the server from handling it correctly. Your very best strategy for figuring out why a request isn't working is to use the tools provided by the API team itself -- consoles, sample code, test tools -- to see what a successful request looks like. For instance, Mashery provides IO/Docs, an interactive explorer, for USA Today and the other APIs it hosts. Similarly, Apigee has a console for Twitter and many other APIs. Both tools give you the ability to see successful calls without writing any code. Check out the headers, URL, and body of those requests; if you can make your request match it's going to succeed.
4XX errors. If the response you receive is a 4xx error, your request isn't what the server is expecting to see. Here's a quick rundown of what these specific codes mean.