« ANNOUNCE : Axis 1.3 Release | Main | Is OptimizedMimeSerialization part of WS-Policy spec? »

REST API for Yahoo Web Search

Inspired by Dave Orchard's effort to represent Yahoo Web Search in WSDL 2.0, i was thinking about how we could support codegen in Axis2.0 for REST-style services. Before we can do that we need a REST-style API that's easy to use. So i ping-ed our REST guru, Mr. Mark Baker. Here's an API that we came up with.

Step #1: Use scomp in xmlbeans to generate code from the xsd. Let's assume that it generates com.yahoo.search.api.ResultSet class

Step #2: Write sample code to invoke the "webSearch"

import com.yahoo.search.api.ResultSet;

try {
Message m = new Message("http://api.search.yahoo.com/WebSearchService/V1/webSearch");
m.addParam("appid","YahooDemo");
m.addParam("query","madonna");
m.addParam("results","2");
m.setResultParam(ResultSet.class);
ResultSet set = (ResultSet) m.invoke("GET");
} catch (HTTPClientException e){
System.out.println("You did something wrong: " + e.getCode());
System.out.println("Error Message:" + m.getResponse().xpath("/Error/Message"));
} catch (HTTPServerException e){
System.out.println("The server did something wrong: " + e.getCode());
System.out.println("Error Message:" + m.getResponse().xpath("/Error/Message"));
}


Notes:

  • 4xx HTTP error codes are translated to HTTPClientException
  • 5xx HTTP error codes are translated to HTTPServerException
  • Yahoo Error Message details are here.
  • If the developer just needs tiny bit from the response and does not want to do databinding, they can just use xpath to extract the relevant portion using xpath. (similar to how we extract the error message)

Does this make sense? Comments? Concerns?

TrackBack

TrackBack URL for this entry:
http://blogs.cocoondev.org/MT/mt-tb.cgi/2564

Listed below are links to weblogs that reference REST API for Yahoo Web Search:

» tramadol from tramadol
[Read More]

» buy bentyl from buy bentyl
[Read More]

Comments

Great stuff! I'm looking forward to publish REST services in Geronimo for AJAX clients.

Post a comment