NO APP IS AN ISLAND Stewart Gleadow @stewgleadow stew@rea-group.com http://www.flickr.com/photos/markselliott/48699538/
Mobile APIs: More than just object.to_json Stewart Gleadow @stewgleadow stew@rea-group.com http://www.flickr.com/photos/markselliott/48699538/
NO APP IS AN ISLAND Stewart Gleadow @stewgleadow stew@rea-group.com http://www.flickr.com/photos/markselliott/48699538/
›❰ Mobile APIs and REST ›❰ Discoverable iOS APIs ›❰ Evolvin g APIs and mobile apps ›❰ Simple apps, smart backends
›❰ Mobile APIs and REST ›❰ Discoverable iOS APIs ›❰ Evolvin g APIs and mobile apps ›❰ Simple apps, smart backends
Is there an API for that? Can I see your API?
POST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 SOAPAction: "http://www.w3.org/2003/05/soap-envelope" <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Header> </soap:Header> <soap:Body> <m:GetStockPrice xmlns:m="http://www.example.org/stock"> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope>
We have a REST API , just construct one of these “RESTful calls”
THAT’S NOT AN API http://schmidtbrotherscutlery.com/blo g /ta g /crocodile-dundee/ http://www.flickr.com/photos/juan-alo g ico/10935384913/
THAT’S NOT AN API http://schmidtbrotherscutlery.com/blo g /ta g /crocodile-dundee/ http://www.flickr.com/photos/juan-alo g ico/10935384913/
How should we build our API ?
Level 0 Level 1 Level 2 Level 3
Level 0 The swamp of POX Level 1 Level 2 Level 3
Level 0 The swamp of POX Level 1 URIs and Resources Level 2 Level 3
Level 0 The swamp of POX Level 1 URIs and Resources Level 2 HTTP verbs and status codes Level 3
Level 0 The swamp of POX Level 1 URIs and Resources Level 2 HTTP verbs and status codes Level 3 Hypermedia controls
Roy Fieldin g - http://roy. g biv.com/untan g led/2008/rest-apis-must-be-hypertext-driven
“What needs to be done to make the REST architectural style clear on the notion that hypertext is a constraint ?” Roy Fieldin g - http://roy. g biv.com/untan g led/2008/rest-apis-must-be-hypertext-driven
“What needs to be done to make the REST architectural style clear on the notion that hypertext is a constraint ?” “Is there some broken manual somewhere that needs to be fixed ?” Roy Fieldin g - http://roy. g biv.com/untan g led/2008/rest-apis-must-be-hypertext-driven
“What needs to be done to make the REST architectural style clear on the notion that hypertext is a constraint ?” “Is there some broken manual somewhere that needs to be fixed ?” “Please try to adhere to them or choose some other buzzword for your API. ” Roy Fieldin g - http://roy. g biv.com/untan g led/2008/rest-apis-must-be-hypertext-driven
This g uy is possibly an island… http://www.flickr.com/photos/50144889@N08/8711099493/
›❰ Mobile APIs and REST ›❰ Discoverable iOS APIs ›❰ Evolvin g APIs and mobile apps ›❰ Simple apps, smart backends
Navi g atin g your API http://www.flickr.com/photos/calsidyrose/4925267732/
Navi g atin g your API The location of service endpoints chan g e Paths to resources within a service chan g e http://www.flickr.com/photos/calsidyrose/4925267732/
HAL JSON : Standardized hypermedia links in JSON
Example: Sign in and retrieve user details
Sign in response Sign in request POST “http://example.com/session” HTTP/1.1 201 Created { { email : "dundee", user_id : “c3Rld0ByZWEtZ3Jvd” password : "password" } }
Sign in response Sign in request POST “http://example.com/session” HTTP/1.1 201 Created { { email : "dundee", user_id : “c3Rld0ByZWEtZ3Jvd” password : "password" } } Which actions are available now? Where do I perform those actions?
Sign in response Sign in request POST “http://example.com/session” HTTP/1.1 201 Created { { email : "dundee", user_id : “c3Rld0ByZWEtZ3Jvd” password : "password" } } Which actions are available now? Where do I perform those actions?
Sign in & get details from an iOS client NSDictionary *params = @{ @"email" : @"dundee", @"password" : @"password" }; self.manager = [AFHTTPRequestOperationManager manager]; [self.manager POST:@"http://example.com/session" parameters:params success:^(AFHTTPRequestOperation *op, NSDictionary *response) { self.userId = response[@"user_id"]; } failure:nil];
Sign in & get details from an iOS client NSDictionary *params = @{ @"email" : @"dundee", @"password" : @"password" }; self.manager = [AFHTTPRequestOperationManager manager]; [self.manager POST:@"http://example.com/session" parameters:params success:^(AFHTTPRequestOperation *op, NSDictionary *response) { self.userId = response[@"user_id"]; } failure:nil]; NSString *detailsUrl = [NSString stringWithFormat:@"http://example.com/details?id=%@", self.userId]; [self.manager GET:detailsUrl parameters:nil success:^(AFHTTPRequestOperation *op, NSDictionary *response) { self.name.text = response[@"name"]; self.phone.text = response[@"phone"]; } failure:nil];
Sign in & get details from an iOS client NSDictionary *params = @{ @"email" : @"dundee", @"password" : @"password" }; self.manager = [AFHTTPRequestOperationManager manager]; [self.manager POST:@"http://example.com/session" parameters:params success:^(AFHTTPRequestOperation *op, NSDictionary *response) { self.userId = response[@"user_id"]; } failure:nil]; NSString *detailsUrl = [NSString stringWithFormat:@"http://example.com/details?id=%@", self.userId]; [self.manager GET:detailsUrl parameters:nil success:^(AFHTTPRequestOperation *op, NSDictionary *response) { self.name.text = response[@"name"]; self.phone.text = response[@"phone"]; } failure:nil];
Sign in & get details from an iOS client NSDictionary *params = @{ @"email" : @"dundee", @"password" : @"password" }; self.manager = [AFHTTPRequestOperationManager manager]; [self.manager POST:@"http://example.com/session" parameters:params success:^(AFHTTPRequestOperation *op, NSDictionary *response) { self.userId = response[@"user_id"]; } failure:nil]; NSString *detailsUrl = [NSString stringWithFormat:@"http://example.com/details?id=%@", self.userId]; [self.manager GET:detailsUrl parameters:nil success:^(AFHTTPRequestOperation *op, NSDictionary *response) { self.name.text = response[@"name"]; self.phone.text = response[@"phone"]; } failure:nil];
Sign in & get details from an iOS client NSDictionary *params = @{ @"email" : @"dundee", @"password" : @"password" }; self.manager = [AFHTTPRequestOperationManager manager]; [self.manager POST:@"http://example.com/session" parameters:params success:^(AFHTTPRequestOperation *op, NSDictionary *response) { self.userId = response[@"user_id"]; } failure:nil]; NSString *detailsUrl = [NSString stringWithFormat:@"http://example.com/details?id=%@", self.userId]; [self.manager GET:detailsUrl parameters:nil success:^(AFHTTPRequestOperation *op, NSDictionary *response) { self.name.text = response[@"name"]; self.phone.text = response[@"phone"]; } failure:nil];
Response HTTP/1.1 201 Created { user_id : “c3Rld0ByZWEtZ3Jvd”, _links : { details : { href : “http://example.com/users/c3Rld0ByZWEtZ3Jvd/details” } } }
Response HTTP/1.1 201 Created { user_id : “c3Rld0ByZWEtZ3Jvd”, _links : { details : { href : “http://example.com/users/c3Rld0ByZWEtZ3Jvd/details” } } } Which actions are available now? Where do I perform those actions?
Response HTTP/1.1 201 Created { user_id : “c3Rld0ByZWEtZ3Jvd”, _links : { details : { href : “http://example.com/users/c3Rld0ByZWEtZ3Jvd/details” } } } Which actions are available now? Where do I perform those actions?
Response HTTP/1.1 201 Created { user_id : “c3Rld0ByZWEtZ3Jvd”, _links : { details : { href : “http://example.com/users/c3Rld0ByZWEtZ3Jvd/details” } } } Which actions are available now? Where do I perform those actions?
Recommend
More recommend