Skip to content

Latest commit

 

History

History
73 lines (50 loc) · 3 KB

2015_09_19.md

File metadata and controls

73 lines (50 loc) · 3 KB

Objectives

  • What is an API
  • What is an HTTP request?
  • What are common HTTP request types

Keynote

http://slides.com/mikekavouras/introduction-to-apis/live#/

Classes

NSURLSession
NSURLSession documentation

The primary job of an instance of NSURLSession is to create and manage one or many instances of NSURLSessionTask.

NSURLSessionTask
NSURLSessionTask documentation

An instance of NSURLSessionTask can represent 1 of 3 different tasks:

  • Data tasks request a resource
  • Upload tasks are like data tasks, except that they make it easier to provide a request body so you can upload data before retrieving the server’s response
  • Download tasks download a resource directly to a file on disk.

NSURL
NSURL documentation
An NSURL object represents a URL that can potentially contain the location of a resource on a remote server, the path of a local file on disk, or even an arbitrary piece of encoded data.

NSURLResponse
NSURLResponse documentation
The NSURLResponse class encapsulates the metadata associated with the response to a a URL load request in a manner independent of protocol and URL scheme.

NSURLRequest
NSURLRequest documentation
NSURLRequest objects represent a URL load request in a manner independent of protocol and URL scheme.

Tutorial: http://code.tutsplus.com/tutorials/networking-with-nsurlsession-part-1--mobile-21394

Example:

Create a session

NSURLSession *session = [NSURLSession sharedSession];

Create a URL

NSURL *url = [NSURL   URLWithString:@"https://itunes.apple.com/search?term=apple&media=software"];

Create a task

NSURLSessionDataTask *dataTask = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
  NSLog(@"%@", json);
}];

Kick off the task

[task resume];

Exercises

Instagram List

  • Populate a table view with the latest posts from Instagram with the tag '#nofilter'
  • Add a refresh button to the navigation bar. When tapped, fetch the latest posts and reload the table view