What Is REST?
Feel free to search the blogosphere all you want using the Technorati Web page. However, as a Web application developer, you might want to automate that search or enable your Web page visitors to view information retrieved from the blogosphere based on their own search criteria.
To make that happen, use the Technorati API. Like many APIs on the Internet, the Technorati API uses REST.
REST is an acronym for Representational State Transfer. The full explanation of everything entailed in a proper REST definition is outside of the scope of this article; however, it is available elsewhere on IBM developerWorks (see the links provided in Resources). For the subject covered here, it is sufficient to state that REST enables developers to access information and resources using a simple HTTP invocation.
Think of REST this way: To obtain domain-specific data, you simply point a URL to a specific location. For the purposes of this article, that’s really all it is. You can also think of it as a simplified Web service, but if you say that too loudly around the wrong people, you might find yourself in the middle of a debate.
In reference to the subject at hand, the Technorati API is a REST service that enables users to point to a specific URL and retrieve a variety of articles from the blogosphere that meet the criteria specified in the URL. This enables you, as a developer, to accept input within a Web application and dynamically query the blogosphere based on that input using a simple URL that encodes the input into a format the API understands.
This is a fairly simple URL with only two request parameters.
Note that the actual Technorati API function is the word that follows the final slash (
search). This indicates, unsurprisingly, that this REST invocation will perform a search against the blogosphere.
The first parameter is the key. The actual key used varies from user to user and is not really the
xxxx character string. To obtain the key that you will use, you need to register with Technorati and request a key. Fortunately this is easy and free. Unfortunately, this means that you cannot simply copy and paste the URLs from this article into a browser and see the results. You have to substitute your own key for this
The second request parameter is the actual query. Just like in the manual example, the search uses the keyword
After you substitute your own key for the xxxx string, you can then plug that URL into a Web browser and see what results are returned. Your results will vary depending on your Web browser brand and version. Whatever the results on the screen, it’s best to right click on the page and select View Source to view the actual XML that is returned.
While the actual contents will also vary based on when your query is executed, the results should resemble Listing 2.
Listing 2. Output from a simple search (partial output)
<?xml version="1.0" encoding="utf-8"?> <!-- generator="Technorati API version 1.0 /search" --> <!DOCTYPE tapi PUBLIC "-//Technorati, Inc.//DTD TAPI 0.02//EN" "http://api.technorati.com/dtd/tapi-002.xml"> <tapi version="1.0"> <document> <result> <query>Obama</query> <querycount>2270581</querycount> <rankingstart></rankingstart> </result> <item> <weblog> <name>Critica Pura</name> <url>http://criticapura.com</url> <rssurl>http://criticapura.com/feed/</rssurl> <atomurl></atomurl> <inboundblogs>7</inboundblogs> <inboundlinks>10</inboundlinks> <lastupdate>2009-06-21 17:13:23 GMT</lastupdate> </weblog> <title>Jib Jab Obama</title> <excerpt>Try JibJab Sendables</excerpt> <created>2009-06-21 17:13:23 GMT</created> <permalink>http://criticapura.com/2009/06/jib-jab-obama/</permalink> </item> ...
Interestingly enough, the first query result as of this writing is a foreign language blog entry (at least, foreign to those who speak English).
result element provides metadata information about the query results. The
query child provides the actual query keyword. The
querycount child provides the number of articles from the blogosphere that matched the query.
item elements follow the
result element. Each
item element corresponds to a blog article that matched the search criteria.
weblog element provides information about the blog itself. This is information about the entire blog as opposed to just the article that matched the criteria. Table 1 describes the
weblog child elements.
weblog child elements
||Actual name of the blog itself|
||URL of the blog|
||URL of the Really Simple Syndication (RSS) feed for that blog|
||URL of the Atom feed for that blog|
||Number of blogs that link to that blog|
||Number of external sites that link back to that blog|
||Date and time the blog was last updated|
||Actual title of the blog article|
||Synopsis of the blog article|
||Date and time the article was written|
||URL for the blog article|