Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 1.46 KB

README.md

File metadata and controls

46 lines (32 loc) · 1.46 KB

HastyAPI

HastyAPI makes it easy to write code to interact with web APIs.

It'll save you writing lots of tedious boilerplate code to make HTTP web requests, and process XML and JSON. By providing high-level, dynamic functions, it lets you concentrate on the web API itself.

Examples

Getting a URL

var text = new APIRequest("http://www.google.com").Get().Text;

Posting data to a URL

var result = new APIRequest("https://www.googleapis.com/urlshortener/v1/url")
    .WithData(@"{ ""longUrl"":""http://www.google.com/"" }", "application/json")
    .Post()
    .Text;

or, you could use the WithJSON shortcut to do the same thing:

var result = new APIRequest("https://www.googleapis.com/urlshortener/v1/url")
    .WithJSON(new { longUrl = "http://www.google.com/" })
    .Post()
    .Text;

value of result:

{
  "kind": "urlshortener#url",
  "id": "http://goo.gl/fbsS",
  "longUrl": "http://www.google.com/"
}

Using JSON data returned from the API_

var clicks = new APIRequest("https://www.googleapis.com/urlshortener/v1/url")
    .WithForm(new { shortUrl = "http://goo.gl/fbsS", projection = "FULL" })
    .Get()
    .AsJSON().analytics.allTime.shortUrlClicks; // <-- dynamic!

// note: WithForm automatically issues querystring variables for GET requests
// you could also do:
//   new APIRequest("https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl.fbsS&projection=FULL")