Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JSON Web API Consumption

JSON Web API Consumption

The web is packed full of web APIs just waiting to be consumed. Sites such as Meetup, GitHub, Twitter, LinkedIn, and Facebook to name a few all have developer APIs that can be used programmatically to consume the data contained within their site. By implementing their APIs in similar fashions using REST, JSON, and OAuth, the ease at which these APIs can be consumed is amazing.

For this talk, I am going to discuss and demonstrate how to consume GitHub’s RESTful web API using web resources, NuGet packages, the .NET framework, and a few lines of C# code.

Scott Smith

June 25, 2012
Tweet

More Decks by Scott Smith

Other Decks in Programming

Transcript

  1. Help yourself to food and drink Mix, mingle, and chat

    Thanks to Front Porch for the food, drink, and location Welcome
  2. Agenda • Introduction • JSON • REST and RESTful Web

    Services • Github’s REST API • Q&A
  3. The web is packed full of web APIs just waiting

    to be consumed. Sites such as Meetup, GitHub, Twitter, LinkedIn, and Facebook to name a few all have developer APIs that can be used programmatically to consume the data contained within their site. By implementing their APIs in similar fashions using REST, JSON, and OAuth, the ease at which these APIs can be consumed is amazing. For this talk, I am going to discuss how to consume GitHub’s RESTful web API using web resources, NuGet packages, the .NET framework, and a few lines of C# code. Along the way, I will also touch on topics such as JSON, REST, Schemas, and the HTTP protocol. JSON Web API Consumption
  4. A lightweight text-based open standard designed for human-readable data interchange.

    It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects. Despite its relationship to JavaScript, it is language-independent, with parsers available for many languages. JSON – JavaScript Object Notation { "firstName": "John", "lastName" : "Smith", "age" : 25, "address" : { "streetAddress": "21 2nd Street", "city" : "New York", "state" : "NY", "postalCode" : "10021" }, "phoneNumber": [ { "type" : "home", "number": "212 555-1234" }, { "type" : "fax", "number": "646 555-4567" } ] }
  5. A style of software architecture for distributed systems such as

    the World Wide Web. REST has emerged over the past few years as a predominant Web service design model by displacing other design models such as SOAP and WSDL due to its simpler style.  Client-server  Stateless  Cacheable  Layered System  Code and demand (optional)  Uniform interface REST – Representational State Transfer
  6. A RESTful web service is a web service implemented using

    HTTP and the principles of REST. It is a collection of resources, with four defined aspects:  The base URI for the web service such as http://example.com/resources  The content type of the data supported by the web service. This could be JSON, XML, or any other valid Internet media type  The set of operations supported by the web service such as GET, PUT, POST, or DELETE.  The API must be hypertext driven. RESTful Web Services
  7. Resource GET PUT POST DELETE Collection URI, such as http://example.com/resources/

    List the URIs and perhaps other details of the collection's members. Replace the entire collection with another collection. Create a new entry in the collection. The new entry's URL is assigned automatically and is usually returned by the operation. Delete the entire collection. Element URI, such as http://example.com/resource/item17 Retrieve a representation of the addressed member named item17 of the collection. Replace the addressed member of the collection, or if it doesn't exist, createit. Treat the addressed member as a collection in its own right and create a new entry in it. Delete the addressed member of the collection. RESTful Web Service HTTP Methods
  8. The first thing that should always be done is to

    seek out documentation for the web API. The current version for GitHub’s is v3 and can be found here: http://developer.github.com/v3/. By looking at the documentation, you will notice that the first page discusses topics such as Schema, Client Errors, HTTP Verbs, Authentication, Pagination, Rate Limiting, and a few others. While all are equally important, we will be focusing on Schema. GitHub’s REST API
  9.  All API access is over HTTPS and accessed from

    the api.github.com domain.  All data is sent and received as JSON.  Blank fields are included as null instead of being omitted.  All timestamps are returned in ISO 8601 format:  YYYY-MM-DDTHH:MM:SSZ GitHub’s REST API Schema
  10.  Scott Smith  [email protected]  Blog: http://scottksmith95.wordpress.com/2012/05/01/json-web-api-consumption/  Code:

    https://github.com/scottksmith95/JSON-Web-API-Consumption  Gists: https://gist.github.com/scottksmith95  Slides: https://speakerdeck.com/u/scottksmith95 Resources