RESTful Live Search Service

Live Search finally gets a REST head and JSON-based API ... and testing the C# 4.0 dynamic RestClient against it (and Google Search) to see if it holds up to these services...

Earlier today, Live Search released a simple REST and JSON-based API for performing search with full flexibility for developers in terms of how to use the results (code named "Silk Road"). The previous API happened to be SOAP-based. Cool (and finally)! Check out the general documentation and the JSON example.

In brief, you issue a request to http://api.search.live.net/json.aspx?AppId={appID}&Market=en-US&Query={query_words}&Sources=web, and you get back a JSON structure as the response that looks like the following:

{
  "SearchResponse": {
    ...
    "Web": {
      "Total": 100,
      "Offset": 0,
      "Results": [
        {
          "Title": "...",
          "Description": "...",
          "Url": "...",
          "DisplayUrl": "...",
          "DateTime": "...",
          "Rank": ...
        }
      ]
    }
  }
}

My immediate thought was would my recent experimentation with REST via dynamic C# programming and turning dynamic method invokation into HTTP requests just work? In fact, can I use this new Live Search API without building a strongly typed wrapper? It turns out the answers are yes - the dynamic RestClient just worked. Here is my snippet of C# code:

dynamic liveSearch =
    new RestClient("http://api.search.live.net/json.aspx?AppId={appID}&Market=en-US&Sources=web",
                   RestClientMode.Json);
liveSearch.appID = AppSettings.Default.LiveSearchApiKey;

dynamic searchOptions = new JsonObject();
searchOptions.Query = "seattle";
dynamic response = liveSearch(searchOptions);

dynamic results = response.SearchResponse.Web.Results;
foreach (dynamic item in results) {
    Console.WriteLine(item.Title);
    Console.WriteLine(item.DisplayUrl);
}

Of course the dynamic REST applies just as well to the equivalent Google's Ajax Search API as well... for completeness:

dynamic googleSearch =
    new RestClient("http://ajax.googleapis.com/ajax/services/search/web?v=1.0",
                   RestClientMode.Json);
dynamic searchOptions = new JsonObject();
searchOptions.q = "seattle";
dynamic response = googleSearch(searchOptions);

dynamic results = response.responseData.results;
foreach (dynamic item in results) {
    Console.WriteLine(item.titleNoFormatting);
    Console.WriteLine(item.url);
}

I updated the DynamicREST github repository, and also updated the sample code. The snippets above illustrate quite natural looking c# for both making HTTP calls and handling the JSON responses.


[ Tags: | | | | | | | ]
Posted on Friday, 11/14/2008 @ 10:02 PM


Comments

9 comments have been posted.

Thanigainathan.S

Posted on 11/15/2008 @ 11:19 PM
Hi Nikhil,

This post seems to be fine . The greater thing is that the same can be used for Google service. So JSON plays the role here . Thanks for giving th sample code.

Thanks

jayesh

Posted on 12/2/2008 @ 9:28 PM
Hi,
solution is nice one,but it is in c# 4.0 ,can I implement same with c# 3.0?
actually I wanted WADL to represent RESTful web services.
how to use it?
can I have code sample or links which can help me out...
Thanks in advance..

Nikhil Kothari

Posted on 12/10/2008 @ 12:57 PM
Jayesh - you can certainly build a similar rest client that works in c# 3.0, but the point of this implementation was to explicitly highlight the programming model you can achieve when using "dynamic", which is a c# 4.0 feature that is in the works and available in CTP form as of now.

The Q

Posted on 2/16/2009 @ 1:11 AM

jdlaj

Posted on 3/9/2009 @ 4:03 PM
Welcome to (www.warestrade.com) to wholesale and retail!We are specializing in sale of a series of brand products, such as Jardon Nike Adidas LV Gucci Prada Coach Fendi Chanel D&G,etc.Products in clude shoes clothes bags jewelry crafts electronic and so on.We can give you the most prefertial prices.Thanks!

jdlaj

Posted on 3/9/2009 @ 4:03 PM
Welcome to (www.warestrade.com) to wholesale and retail!We are specializing in sale of a series of brand products, such as Jardon Nike Adidas LV Gucci Prada Coach Fendi Chanel D&G,etc.Products in clude shoes clothes bags jewelry crafts electronic and so on.We can give you the most prefertial prices.Thanks!

jdlaj

Posted on 3/9/2009 @ 4:03 PM
Welcome to (www.warestrade.com) to wholesale and retail!We are specializing in sale of a series of brand products, such as Jardon Nike Adidas LV Gucci Prada Coach Fendi Chanel D&G,etc.Products in clude shoes clothes bags jewelry crafts electronic and so on.We can give you the most prefertial prices.Thanks!

Nina

Posted on 3/23/2009 @ 6:27 AM
(www.warestrade.com)Hello.We are chinese wholesalers.Our company is devoted to selling small wares. We are specializing in sale of a series of brand products, such as LV Gucci Prada Coach Fendi Chanel D&G etc.Products include shoes handbags purse jewelry and so on.We wholesale and retail jordan shoes,gucci shoes,nike shoes,puma shoes,adidas shoes,lacoste shoes,sport shoes,sneakers,coach shoes,prada chose,DG shoes.lv shoes,Burberry shoes,paul smith shoes,wholesale and retail lv handbags,gucci handbags,coach handbags,fendi handbags,juicy handbags,chanel handbags, wholesale and retail lv boots,gucci boots,fendi boots,prada boots,UGG boots,wholesale cheap lacoste shirts,polo shirts,AF shirts,DG shirts,EDshirts.wholesale and retail lv coach slippers,gucci sandals,chanel sandals.wholesale juicy jeans,juicy handbags,juicy shirts,ugg handbags and so on.All the goods we purchase directly from manufacturers,so the price is very low.You can just go to my webstire www.warestrade.com to choose any you want.We also can make products as you ask for.If you will,just give us the sample,We make them for you.Welcome to www.warestrade.com to wholesale and retail! Please contact me at (warestrade at gmail dot com)(TEL 86-13626936130)Thanks!
Best regards!
Mako

Nina

Posted on 3/23/2009 @ 6:27 AM
(www.warestrade.com)Hello.We are chinese wholesalers.Our company is devoted to selling small wares. We are specializing in sale of a series of brand products, such as LV Gucci Prada Coach Fendi Chanel D&G etc.Products include shoes handbags purse jewelry and so on.We wholesale and retail jordan shoes,gucci shoes,nike shoes,puma shoes,adidas shoes,lacoste shoes,sport shoes,sneakers,coach shoes,prada chose,DG shoes.lv shoes,Burberry shoes,paul smith shoes,wholesale and retail lv handbags,gucci handbags,coach handbags,fendi handbags,juicy handbags,chanel handbags, wholesale and retail lv boots,gucci boots,fendi boots,prada boots,UGG boots,wholesale cheap lacoste shirts,polo shirts,AF shirts,DG shirts,EDshirts.wholesale and retail lv coach slippers,gucci sandals,chanel sandals.wholesale juicy jeans,juicy handbags,juicy shirts,ugg handbags and so on.All the goods we purchase directly from manufacturers,so the price is very low.You can just go to my webstire www.warestrade.com to choose any you want.We also can make products as you ask for.If you will,just give us the sample,We make them for you.Welcome to www.warestrade.com to wholesale and retail! Please contact me at (warestrade at gmail dot com)(TEL 86-13626936130)Thanks!
Best regards!
Mako
Post your comment and continue the discussion.