开发者

REST service returning "useful" information for demos

I am looking for a REST service that I could use in demo code. I'd like the service:

  • To take at least one parameter (as a request parameter, or XML PO开发者_StackOverflowSTed as the body of the HTTP request).
  • To return the result as XML (not JSON).
  • To be accessible anonymously (I'll call the service in sample code, so I don't want to put my key in the code, or request users to get a key).

When the Twitter API supported XML (not just JSON), I was typically using their search API. But really anything mainstream enough, easy enough to understand will do (information about zip code, weather for a city…).


If you are using .Net, why don't you just create a tiny MVC application that has a controller that exposes a method that returns some sort of formatted XML? That way you can run the whole thing locally.

EDIT:

You know, I think you can use Google Maps API without a key. I created a test project a couple of days ago. Here is a .Net code snippet (only included so that you can see how I am calling the service):

private static string GetString(Uri requestUri)
{
   var output = string.Empty;

   var response = WebRequest.Create(requestUri).GetResponse();
   var stream = response.GetResponseStream();
   if (stream != null)
   {
      using (var reader = new StreamReader(stream))
      {
         output = reader.ReadToEnd();
         reader.Close();
      }
   }
   response.Close();
   return output;
}

I pass in a uri with a url:

https://maps.googleapis.com/maps/api/directions/xml?mode=walking&origin={0},{1}&destination={2},{3}&sensor=false

Where {0},{1} are the first lat/long, and {2},{3} are the second. I am not attaching a key to this and it worked for testing. My method returns a string that later I handle like so:

var response = XDocument.Parse(GetString(request));

which gives me back xml. Again, I still recommend just creating your own web app and then deploying it somewhere publicly accessible (either in a LAN or on the web), but if you just need a web service to return XML you can use that.


The Yahoo! Weather API can be used for this. It takes a location as a request parameter and returns the weather forecast for that location as XML. It also returns weather information as HTML, which you could display as-is to the user. You can see an example of this below. Also make sure that you respect the term of use described at the bottom of the Weather API documentation page.

REST service returning "useful" information for demos

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜