Yahoo Local Search Service Integration Part 1: Intro
Today I'm beginning a series of posts on using the Yahoo local search service and embedding it within an ASPX page. The Yahoo local search service finds businesses within a local community based on city/state or zip code lookups. This service also takes a range of other parameters to specify the range to use, the result set limits, the type of response (JSON, XML), and so on. More information can be found here: http://developer.yahoo.com/search/local/V3/localSearch.html.
Yahoo, as most other REST and web service API's, require the use of an AppID that specifies the application querying it. This is a common way to track usage. However, Yahoo uses the YahooDemo ID for demo purposes, and that's what we'll do here. Not only will I illustrate how to query and get the data, but I'll try to show a few alternatives, plus I'll display it in a way that's more "eye candy" so to speak.
For REST calls, the approach we can take is to use the WebRequest and WebResponse objects to process the HTTP request and response. Posting and retrieving requests can be done using:
WebRequest request = HttpWebRequest.Create(url);
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
return reader.ReadToEnd();
Using the specified REST url, the downloaded response is retrieved using a HttpWebResponse, along with the StreamReader that extracts the information from the response stream. And thus, the content (which this series will use JSON) gets extracted as a string via the ReadToEnd() method.
How the JSON gets to the client for JavaScript to process doesn't matter at the moment; at this moment, we're focused solely on the process reading the JSON data. The URL we'll extract the data from is:
http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=YahooDemo&query=barber&zip=15239&results=10&output=json
And from this, we'll begin to look at how we're going to process the data.