SlideShare una empresa de Scribd logo
1 de 56
Descargar para leer sin conexión
Network Connected
hypermedia for the iOS developer




Kevin O’Neill
PlayUp Pty Ltd
Roadmap
• Some background
• Introduction to hypermedia
• Consuming a hypermedia API
• Bit’s and Pieces


                               SWIPE CONFERENCE 2012
CTO PlayUp



             SWIPE CONFERENCE 2012
Blood



        SWIPE CONFERENCE 2012
This will be an introduction



                         SWIPE CONFERENCE 2012
Opinionated



              SWIPE CONFERENCE 2012
ReST



       SWIPE CONFERENCE 2012
SWIPE CONFERENCE 2012
It’s been mutated to the point
     of being meaningless


                          SWIPE CONFERENCE 2012
CRUD = ReST



              SWIPE CONFERENCE 2012
URL Patterns = REST



                      SWIPE CONFERENCE 2012
http://example.com/products/<id>




                                   SWIPE CONFERENCE 2012
Well No



          SWIPE CONFERENCE 2012
Hypermedia API’s



                   SWIPE CONFERENCE 2012
The Good



           SWIPE CONFERENCE 2012
Loose Coupling



                 SWIPE CONFERENCE 2012
Simplicity / Uniformity


                          SWIPE CONFERENCE 2012
Scale better



               SWIPE CONFERENCE 2012
The Bad



          SWIPE CONFERENCE 2012
Not the most succinct form



                       SWIPE CONFERENCE 2012
Cache invalidation is hard



                        SWIPE CONFERENCE 2012
It takes more thought



                        SWIPE CONFERENCE 2012
What is a hypermedia API



                      SWIPE CONFERENCE 2012
Use HTTP Properly*



                     SWIPE CONFERENCE 2012
Use links to guide clients
   through processes

                        SWIPE CONFERENCE 2012
"REST is software design on the scale of
  decades: every detail is intended to promote
 software longevity and independent evolution.
Many of the constraints are directly opposed to
short-term efficiency. Unfortunately, people are
  fairly good at short-term design, and usually
    awful at long-term design." - Roy Fielding

                                          SWIPE CONFERENCE 2012
Consuming a Hypermedia API



                      SWIPE CONFERENCE 2012
{
	
  	
  "title":	
  "Raiders	
  vs	
  Bulldogs",
	
  	
  "short_title":	
  "RAI	
  vs	
  BUL",

	
  	
  "scheduled_start_time":	
  "2012-­‐08-­‐24T09:35:00Z",
	
  	
  "start_time":	
  "2012-­‐08-­‐24T09:35:00Z",
	
  	
  "end_time":	
  "2012-­‐08-­‐24T12:24:54Z",
	
  	
  
	
  	
  "clock":	
  {
	
  	
  	
  	
  "summary":	
  "2ND	
  61:56",
	
  	
  	
  	
  "minutes":	
  61,
	
  	
  	
  	
  "seconds":	
  56,
	
  	
  	
  	
  "period":	
  2
	
  	
  },

	
  	
  ...

                                                                 SWIPE CONFERENCE 2012
Content-­‐Type




                 SWIPE CONFERENCE 2012
Content-­‐Type

application/json




                   SWIPE CONFERENCE 2012
Content-­‐Type

application/vnd.example.contest.rugby_league+json




                                                    SWIPE CONFERENCE 2012
Strategy



           SWIPE CONFERENCE 2012
@protocol	
  HTTPResponseHandler	
  <NSObject>

-­‐	
  (void)handle:(NSHTTPURLResponse	
  *)response
	
  	
  	
  	
  forRequest:(id	
  <RequestToken>)request;

@end


@interface	
  RegistryHandler	
  :	
  NSObject	
  <HTTPResponseHandler>

-­‐	
  (void)registerHandler:(id<HTTPResponseHandler>)handler
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  for:(id<TypeMatcher>)matcher;

@end



                                                                                                         SWIPE CONFERENCE 2012
Errors



         SWIPE CONFERENCE 2012
 	
  "scores":	
  [
	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  "total":	
  34,
	
  	
  	
  	
  	
  	
  "summary":	
  "34",
	
  	
  	
  	
  	
  	
  "team":	
  {
	
  	
  	
  	
  	
  	
  	
  	
  ":href":	
  "http://example.com/teams/569",
	
  	
  	
  	
  	
  	
  	
  	
  ":type":	
  "application/vnd.example.sport.team+json"
	
  	
  	
  	
  	
  	
  	
  	
  ":links"	
  [
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "rel":	
  "alternate",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "href":	
  "http://example.com/teams/569.xml"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "type":	
  "application/vnd.example.sport.team+xml"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "rel":	
  "alternate",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "href":	
  "http://example.com/teams/569.html"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "type":	
  "text/html"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }
                                                                                         SWIPE CONFERENCE 2012
 	
  "scores":	
  [
	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  "total":	
  34,
	
  	
  	
  	
  	
  	
  "summary":	
  "34",
	
  	
  	
  	
  	
  	
  "team":	
  {
	
  	
  	
  	
  	
  	
  	
  	
  ":href":	
  "http://example.com/teams/569",
	
  	
  	
  	
  	
  	
  	
  	
  ":type":	
  "application/vnd.example.sport.team+json"
	
  	
  	
  	
  	
  	
  	
  	
  ":links"	
  [
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "rel":	
  "alternate",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "href":	
  "http://example.com/teams/569.xml"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "type":	
  "application/vnd.example.sport.team+xml"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "rel":	
  "alternate",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "href":	
  "http://example.com/teams/569.html"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "type":	
  "text/html"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }
                                                                                         SWIPE CONFERENCE 2012
 	
  "scores":	
  [
	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  "total":	
  34,
	
  	
  	
  	
  	
  	
  "summary":	
  "34",
	
  	
  	
  	
  	
  	
  "team":	
  {
	
  	
  	
  	
  	
  	
  	
  	
  ":href":	
  "http://example.co/t/d/dogs.json",
	
  	
  	
  	
  	
  	
  	
  	
  ":type":	
  "application/vnd.example.sport.team+json",
	
  	
  	
  	
  	
  	
  	
  	
  ":links"	
  [
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "rel":	
  "alternate",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "href":	
  "http://example.com/teams/569.xml"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "type":	
  "application/vnd.example.sport.team+xml"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "rel":	
  "alternate",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "href":	
  "http://example.com/teams/569.html"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "type":	
  "text/html"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }
                                                                                         SWIPE CONFERENCE 2012
Versioning and Alternates



                       SWIPE CONFERENCE 2012
 	
  "scores":	
  [
	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  "total":	
  34,
	
  	
  	
  	
  	
  	
  "summary":	
  "34",
	
  	
  	
  	
  	
  	
  "team":	
  {
	
  	
  	
  	
  	
  	
  	
  	
  ":href":	
  "http://example.com/teams/569",
	
  	
  	
  	
  	
  	
  	
  	
  ":type":	
  "application/vnd.example.sport.team+json",
	
  	
  	
  	
  	
  	
  	
  	
  ":links"	
  [
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "rel":	
  "alternate",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "href":	
  "http://example.com/teams/569.xml"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "type":	
  "application/vnd.example.sport.team+xml"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "rel":	
  "alternate",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "href":	
  "http://example.com/teams/569.html"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "type":	
  "text/html"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }
                                                                                         SWIPE CONFERENCE 2012
Accept

application/vnd.example.sport.team+xml




                                         SWIPE CONFERENCE 2012
Accept

application/vnd.example.sport.team+xml,*/*




                                             SWIPE CONFERENCE 2012
 	
  "scores":	
  [
	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  "total":	
  34,
	
  	
  	
  	
  	
  	
  "summary":	
  "34",
	
  	
  	
  	
  	
  	
  "team":	
  {
	
  	
  	
  	
  	
  	
  	
  	
  ":href":	
  "http://example.com/teams/569",
	
  	
  	
  	
  	
  	
  	
  	
  ":type":	
  "application/vnd.example.sport.team+json",
	
  	
  	
  	
  	
  	
  	
  	
  ":links"	
  [
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "rel":	
  "alternate",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "href":	
  "http://example.com/teams/569.xml"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "type":	
  "application/vnd.example.sport.team+xml"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "rel":	
  "alternate",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "href":	
  "http://example.com/teams/569.html"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "type":	
  "text/html"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }
                                                                                         SWIPE CONFERENCE 2012
 	
  NSMutableURLRequest	
  *request	
  =
	
  	
  	
  	
  [[NSMutableURLRequest	
  alloc]	
  initWithURL:url];
	
  	
  [request	
  
	
  	
  	
  	
  	
  setHTTPMethod:@"GET"];
	
  	
  [request	
  
	
  	
  	
  	
  	
  addValue:@"text/html,*/*"	
  forHTTPHeaderField:@"Accept"];




                                                                      SWIPE CONFERENCE 2012
Caching



          SWIPE CONFERENCE 2012
NSURLCache	
  *sharedCache	
  =	
  
	
  	
  [[NSURLCache	
  alloc]
	
  	
  	
  	
  initWithMemoryCapacity:kMemoryCacheSize
	
  	
  	
  	
  diskCapacity:kDiskCacheSize	
  
	
  	
  	
  	
  diskPath:cache_path];
	
  	
  	
  	
  
[NSURLCache	
  setSharedURLCache:sharedCache];




                                                          SWIPE CONFERENCE 2012
ETag
"9461cf5ecc0f4df6e880ce76479aba90"

Cache-­‐Control
max-­‐age=15,	
  public

Vary
Accept-­‐Language




                                     SWIPE CONFERENCE 2012
NSMutableURLRequest	
  *request	
  =	
  
	
  	
  
	
  	
  ...

[request	
  setValue:etag	
  forHTTPHeaderField:@"If-­‐None-­‐Match"];




                                                               SWIPE CONFERENCE 2012
NSMutableURLRequest	
  *request	
  =	
  
	
  	
  
	
  	
  ...

[request	
  setValue:etag	
  forHTTPHeaderField:@"If-­‐None-­‐Match"];

[request	
  setCachePolicy:
	
  	
  NSURLRequestReloadIgnoringLocalCacheData];




                                                               SWIPE CONFERENCE 2012
static	
  NSUInteger	
  calc_timeout(NSHTTPURLResponse	
  *response)	
  {
	
  	
  NSUInteger	
  new_timeout	
  =	
  k_default_expires;
	
  	
  
	
  	
  NSString	
  *cache_control	
  =	
  [[response	
  allHeaderFields]	
  valueForKey:@"Cache-­‐Control"];
	
  	
  if	
  (nil	
  !=	
  cache_control)
	
  	
  {
	
  	
  	
  	
  NSRange	
  maxage_range	
  =	
  [cache_control	
  rangeOfString:@"max-­‐age="];
	
  	
  	
  	
  if	
  (maxage_range.location	
  !=	
  NSNotFound)
	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  NSString	
  *timeout_str	
  =	
  [cache_control	
  substringFromIndex:NSMaxRange(maxage_range)];
	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  NSRange	
  comma_range	
  =	
  [timeout_str	
  rangeOfString:@","];
	
  	
  	
  	
  	
  	
  if	
  (NSNotFound	
  !=	
  comma_range.location)
	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  timeout_str	
  =	
  [timeout_str	
  substringToIndex:comma_range.location];
	
  	
  	
  	
  	
  	
  }
	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  new_timeout	
  =	
  (NSUInteger)[timeout_str	
  integerValue];
	
  	
  	
  	
  }
	
  	
  }
	
  	
  
	
  	
  return	
  new_timeout;
}



                                                                                                            SWIPE CONFERENCE 2012
Bits and Pieces



                  SWIPE CONFERENCE 2012
Test from other countries



                       SWIPE CONFERENCE 2012
Charles is your friend



                         SWIPE CONFERENCE 2012
HTTPShouldUsePipelining



                     SWIPE CONFERENCE 2012
gzip encoding is your friend


                         SWIPE CONFERENCE 2012
Proxies Screw You



                    SWIPE CONFERENCE 2012
Questions
Kevin O’Neill
CTO - PlayUp
@kevinoneill
kevin@playup.com




                   SWIPE CONFERENCE 2012

Más contenido relacionado

Similar a Hypermedia for the iOS developer - Swipe 2012

API Technical Writing
API Technical WritingAPI Technical Writing
API Technical WritingSarah Maddox
 
Node in Production at Aviary
Node in Production at AviaryNode in Production at Aviary
Node in Production at AviaryAviary
 
Front End Development for Back End Developers - Denver Startup Week 2017
Front End Development for Back End Developers - Denver Startup Week 2017Front End Development for Back End Developers - Denver Startup Week 2017
Front End Development for Back End Developers - Denver Startup Week 2017Matt Raible
 
David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...
David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...
David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...Codemotion
 
Cdm mil-18 - hypermedia ap is for headless platforms and data integration
Cdm mil-18 - hypermedia ap is for headless platforms and data integrationCdm mil-18 - hypermedia ap is for headless platforms and data integration
Cdm mil-18 - hypermedia ap is for headless platforms and data integrationDavid Gómez García
 
TDC2016POA | Trilha Web - JSON API: não reinvente a roda
TDC2016POA | Trilha Web - JSON API: não reinvente a rodaTDC2016POA | Trilha Web - JSON API: não reinvente a roda
TDC2016POA | Trilha Web - JSON API: não reinvente a rodatdc-globalcode
 
Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)Katy Slemon
 
Lets dance- Dutch Architecture Conference (LAC) 2018
Lets dance- Dutch Architecture Conference (LAC) 2018Lets dance- Dutch Architecture Conference (LAC) 2018
Lets dance- Dutch Architecture Conference (LAC) 2018Yenlo
 
OrchardCMS module development
OrchardCMS module developmentOrchardCMS module development
OrchardCMS module developmentJay Harris
 
PHP on Windows and on Azure
PHP on Windows and on AzurePHP on Windows and on Azure
PHP on Windows and on AzureMaarten Balliauw
 
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbsAWS Chicago
 
Gapand 2017 - Diseñando Arquitecturas Serverless en Azure
Gapand 2017 - Diseñando Arquitecturas Serverless en AzureGapand 2017 - Diseñando Arquitecturas Serverless en Azure
Gapand 2017 - Diseñando Arquitecturas Serverless en AzureAlberto Diaz Martin
 
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...apidays
 
Hypermedia api (HATEOAS)
Hypermedia api (HATEOAS)Hypermedia api (HATEOAS)
Hypermedia api (HATEOAS)MitinPavel
 
Stop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in DrupalStop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in DrupalBjörn Brala
 
Koshy june27 140pm_room210_c_v4
Koshy june27 140pm_room210_c_v4Koshy june27 140pm_room210_c_v4
Koshy june27 140pm_room210_c_v4DataWorks Summit
 
Building a Real-time Data Pipeline: Apache Kafka at LinkedIn
Building a Real-time Data Pipeline: Apache Kafka at LinkedInBuilding a Real-time Data Pipeline: Apache Kafka at LinkedIn
Building a Real-time Data Pipeline: Apache Kafka at LinkedInDataWorks Summit
 

Similar a Hypermedia for the iOS developer - Swipe 2012 (20)

API Technical Writing
API Technical WritingAPI Technical Writing
API Technical Writing
 
Node in Production at Aviary
Node in Production at AviaryNode in Production at Aviary
Node in Production at Aviary
 
Front End Development for Back End Developers - Denver Startup Week 2017
Front End Development for Back End Developers - Denver Startup Week 2017Front End Development for Back End Developers - Denver Startup Week 2017
Front End Development for Back End Developers - Denver Startup Week 2017
 
David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...
David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...
David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...
 
Cdm mil-18 - hypermedia ap is for headless platforms and data integration
Cdm mil-18 - hypermedia ap is for headless platforms and data integrationCdm mil-18 - hypermedia ap is for headless platforms and data integration
Cdm mil-18 - hypermedia ap is for headless platforms and data integration
 
TDC2016POA | Trilha Web - JSON API: não reinvente a roda
TDC2016POA | Trilha Web - JSON API: não reinvente a rodaTDC2016POA | Trilha Web - JSON API: não reinvente a roda
TDC2016POA | Trilha Web - JSON API: não reinvente a roda
 
Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)
 
Android networking-2
Android networking-2Android networking-2
Android networking-2
 
Lets dance- Dutch Architecture Conference (LAC) 2018
Lets dance- Dutch Architecture Conference (LAC) 2018Lets dance- Dutch Architecture Conference (LAC) 2018
Lets dance- Dutch Architecture Conference (LAC) 2018
 
PHP as a Service TDC2019
PHP as a Service TDC2019PHP as a Service TDC2019
PHP as a Service TDC2019
 
Introduction to Hydra
Introduction to HydraIntroduction to Hydra
Introduction to Hydra
 
OrchardCMS module development
OrchardCMS module developmentOrchardCMS module development
OrchardCMS module development
 
PHP on Windows and on Azure
PHP on Windows and on AzurePHP on Windows and on Azure
PHP on Windows and on Azure
 
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 
Gapand 2017 - Diseñando Arquitecturas Serverless en Azure
Gapand 2017 - Diseñando Arquitecturas Serverless en AzureGapand 2017 - Diseñando Arquitecturas Serverless en Azure
Gapand 2017 - Diseñando Arquitecturas Serverless en Azure
 
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
 
Hypermedia api (HATEOAS)
Hypermedia api (HATEOAS)Hypermedia api (HATEOAS)
Hypermedia api (HATEOAS)
 
Stop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in DrupalStop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in Drupal
 
Koshy june27 140pm_room210_c_v4
Koshy june27 140pm_room210_c_v4Koshy june27 140pm_room210_c_v4
Koshy june27 140pm_room210_c_v4
 
Building a Real-time Data Pipeline: Apache Kafka at LinkedIn
Building a Real-time Data Pipeline: Apache Kafka at LinkedInBuilding a Real-time Data Pipeline: Apache Kafka at LinkedIn
Building a Real-time Data Pipeline: Apache Kafka at LinkedIn
 

Hypermedia for the iOS developer - Swipe 2012

  • 1. Network Connected hypermedia for the iOS developer Kevin O’Neill PlayUp Pty Ltd
  • 2. Roadmap • Some background • Introduction to hypermedia • Consuming a hypermedia API • Bit’s and Pieces SWIPE CONFERENCE 2012
  • 3. CTO PlayUp SWIPE CONFERENCE 2012
  • 4. Blood SWIPE CONFERENCE 2012
  • 5. This will be an introduction SWIPE CONFERENCE 2012
  • 6. Opinionated SWIPE CONFERENCE 2012
  • 7. ReST SWIPE CONFERENCE 2012
  • 9. It’s been mutated to the point of being meaningless SWIPE CONFERENCE 2012
  • 10. CRUD = ReST SWIPE CONFERENCE 2012
  • 11. URL Patterns = REST SWIPE CONFERENCE 2012
  • 12. http://example.com/products/<id> SWIPE CONFERENCE 2012
  • 13. Well No SWIPE CONFERENCE 2012
  • 14. Hypermedia API’s SWIPE CONFERENCE 2012
  • 15. The Good SWIPE CONFERENCE 2012
  • 16. Loose Coupling SWIPE CONFERENCE 2012
  • 17. Simplicity / Uniformity SWIPE CONFERENCE 2012
  • 18. Scale better SWIPE CONFERENCE 2012
  • 19. The Bad SWIPE CONFERENCE 2012
  • 20. Not the most succinct form SWIPE CONFERENCE 2012
  • 21. Cache invalidation is hard SWIPE CONFERENCE 2012
  • 22. It takes more thought SWIPE CONFERENCE 2012
  • 23. What is a hypermedia API SWIPE CONFERENCE 2012
  • 24. Use HTTP Properly* SWIPE CONFERENCE 2012
  • 25. Use links to guide clients through processes SWIPE CONFERENCE 2012
  • 26. "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of the constraints are directly opposed to short-term efficiency. Unfortunately, people are fairly good at short-term design, and usually awful at long-term design." - Roy Fielding SWIPE CONFERENCE 2012
  • 27. Consuming a Hypermedia API SWIPE CONFERENCE 2012
  • 28. {    "title":  "Raiders  vs  Bulldogs",    "short_title":  "RAI  vs  BUL",    "scheduled_start_time":  "2012-­‐08-­‐24T09:35:00Z",    "start_time":  "2012-­‐08-­‐24T09:35:00Z",    "end_time":  "2012-­‐08-­‐24T12:24:54Z",        "clock":  {        "summary":  "2ND  61:56",        "minutes":  61,        "seconds":  56,        "period":  2    },    ... SWIPE CONFERENCE 2012
  • 29. Content-­‐Type SWIPE CONFERENCE 2012
  • 30. Content-­‐Type application/json SWIPE CONFERENCE 2012
  • 32. Strategy SWIPE CONFERENCE 2012
  • 33. @protocol  HTTPResponseHandler  <NSObject> -­‐  (void)handle:(NSHTTPURLResponse  *)response        forRequest:(id  <RequestToken>)request; @end @interface  RegistryHandler  :  NSObject  <HTTPResponseHandler> -­‐  (void)registerHandler:(id<HTTPResponseHandler>)handler                                        for:(id<TypeMatcher>)matcher; @end SWIPE CONFERENCE 2012
  • 34. Errors SWIPE CONFERENCE 2012
  • 35.    "scores":  [        {            "total":  34,            "summary":  "34",            "team":  {                ":href":  "http://example.com/teams/569",                ":type":  "application/vnd.example.sport.team+json"                ":links"  [                    {                        "rel":  "alternate",                        "href":  "http://example.com/teams/569.xml"                        "type":  "application/vnd.example.sport.team+xml"                    },                    {                        "rel":  "alternate",                        "href":  "http://example.com/teams/569.html"                        "type":  "text/html"                    } SWIPE CONFERENCE 2012
  • 36.    "scores":  [        {            "total":  34,            "summary":  "34",            "team":  {                ":href":  "http://example.com/teams/569",                ":type":  "application/vnd.example.sport.team+json"                ":links"  [                    {                        "rel":  "alternate",                        "href":  "http://example.com/teams/569.xml"                        "type":  "application/vnd.example.sport.team+xml"                    },                    {                        "rel":  "alternate",                        "href":  "http://example.com/teams/569.html"                        "type":  "text/html"                    } SWIPE CONFERENCE 2012
  • 37.    "scores":  [        {            "total":  34,            "summary":  "34",            "team":  {                ":href":  "http://example.co/t/d/dogs.json",                ":type":  "application/vnd.example.sport.team+json",                ":links"  [                    {                        "rel":  "alternate",                        "href":  "http://example.com/teams/569.xml"                        "type":  "application/vnd.example.sport.team+xml"                    },                    {                        "rel":  "alternate",                        "href":  "http://example.com/teams/569.html"                        "type":  "text/html"                    } SWIPE CONFERENCE 2012
  • 38. Versioning and Alternates SWIPE CONFERENCE 2012
  • 39.    "scores":  [        {            "total":  34,            "summary":  "34",            "team":  {                ":href":  "http://example.com/teams/569",                ":type":  "application/vnd.example.sport.team+json",                ":links"  [                    {                        "rel":  "alternate",                        "href":  "http://example.com/teams/569.xml"                        "type":  "application/vnd.example.sport.team+xml"                    },                    {                        "rel":  "alternate",                        "href":  "http://example.com/teams/569.html"                        "type":  "text/html"                    } SWIPE CONFERENCE 2012
  • 42.    "scores":  [        {            "total":  34,            "summary":  "34",            "team":  {                ":href":  "http://example.com/teams/569",                ":type":  "application/vnd.example.sport.team+json",                ":links"  [                    {                        "rel":  "alternate",                        "href":  "http://example.com/teams/569.xml"                        "type":  "application/vnd.example.sport.team+xml"                    },                    {                        "rel":  "alternate",                        "href":  "http://example.com/teams/569.html"                        "type":  "text/html"                    } SWIPE CONFERENCE 2012
  • 43.    NSMutableURLRequest  *request  =        [[NSMutableURLRequest  alloc]  initWithURL:url];    [request            setHTTPMethod:@"GET"];    [request            addValue:@"text/html,*/*"  forHTTPHeaderField:@"Accept"]; SWIPE CONFERENCE 2012
  • 44. Caching SWIPE CONFERENCE 2012
  • 45. NSURLCache  *sharedCache  =      [[NSURLCache  alloc]        initWithMemoryCapacity:kMemoryCacheSize        diskCapacity:kDiskCacheSize          diskPath:cache_path];         [NSURLCache  setSharedURLCache:sharedCache]; SWIPE CONFERENCE 2012
  • 47. NSMutableURLRequest  *request  =          ... [request  setValue:etag  forHTTPHeaderField:@"If-­‐None-­‐Match"]; SWIPE CONFERENCE 2012
  • 48. NSMutableURLRequest  *request  =          ... [request  setValue:etag  forHTTPHeaderField:@"If-­‐None-­‐Match"]; [request  setCachePolicy:    NSURLRequestReloadIgnoringLocalCacheData]; SWIPE CONFERENCE 2012
  • 49. static  NSUInteger  calc_timeout(NSHTTPURLResponse  *response)  {    NSUInteger  new_timeout  =  k_default_expires;        NSString  *cache_control  =  [[response  allHeaderFields]  valueForKey:@"Cache-­‐Control"];    if  (nil  !=  cache_control)    {        NSRange  maxage_range  =  [cache_control  rangeOfString:@"max-­‐age="];        if  (maxage_range.location  !=  NSNotFound)        {            NSString  *timeout_str  =  [cache_control  substringFromIndex:NSMaxRange(maxage_range)];                        NSRange  comma_range  =  [timeout_str  rangeOfString:@","];            if  (NSNotFound  !=  comma_range.location)            {                timeout_str  =  [timeout_str  substringToIndex:comma_range.location];            }                        new_timeout  =  (NSUInteger)[timeout_str  integerValue];        }    }        return  new_timeout; } SWIPE CONFERENCE 2012
  • 50. Bits and Pieces SWIPE CONFERENCE 2012
  • 51. Test from other countries SWIPE CONFERENCE 2012
  • 52. Charles is your friend SWIPE CONFERENCE 2012
  • 53. HTTPShouldUsePipelining SWIPE CONFERENCE 2012
  • 54. gzip encoding is your friend SWIPE CONFERENCE 2012
  • 55. Proxies Screw You SWIPE CONFERENCE 2012
  • 56. Questions Kevin O’Neill CTO - PlayUp @kevinoneill kevin@playup.com SWIPE CONFERENCE 2012