13
RESTful Hypermedia APIs (Representational State Transfer) Recap of Kevin O’Neill’s talk at YOW night, a review of Meetup API, and a look into HAL+JSON @matt_connolly Wednesday, 3 April 13

RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

RESTful Hypermedia APIs (Representational State Transfer)

Recap of Kevin O’Neill’s talk at YOW night,a review of Meetup API, and

a look into HAL+JSON

@matt_connolly

Wednesday, 3 April 13

Page 2: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

REST API for Mobile Apps

Kevin O’Neill, CTO of Playup. REST API for native mobile apps and browsers.REST wins for:

Caching,Performance / scalability.Use custom media types for backward and forward compatibility

Wednesday, 3 April 13

Page 3: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

REST vs SOAP, XML-RPC, etc

SOAP:Big web.Strongly typed, complex object types.XML wrapping of remote procedure calls.Commonly found in Enterprise Java applications. Client consumes a WSDL interface and makes HTTP POSTs to a service endpoint.

Wednesday, 3 April 13

Page 4: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

XML-RPC:Lighter weight than SOAP, simpler data types.XML wrapping of remote procedure calls.Client makes HTTP POSTs to a service endpoint. Client know the calls available or discovery if server supports “system.listMethods()” and“system.methodSignature(string methodName)”

REST vs SOAP, XML-RPC, etc

Wednesday, 3 April 13

Page 5: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

REST vs SOAP, XML-RPC, etc

REST:much more free.Free use of media types (representations):

JSON, XML, etc.Actions follow HTTP verbs: GET, POST, PUT, DELETE, etc.GET requests are cacheable (performance)Resource identified by a URI.Requests can be routed by URI.

Wednesday, 3 April 13

Page 6: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

Pros and Cons of REST

Pros:Cacheable,Distributable / Routable,Compatibility,Less bandwidth,Simpler for clients,Freedom of media types.

Cons:HTTP overhead,Methods need to map to resources,More requests,Harder to implement well,Freedom of media types.

Wednesday, 3 April 13

Page 7: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

Hypermedia: What’s in a web page

Hypermedia includes text, styles, links, images, etc.

Supports all sorts of different browser capabilities.

Wednesday, 3 April 13

Page 8: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

Hypermedia: The HTML of APIs

SOAP & XML-RPC wrap content in documented XML structure.

Data should be discoverable.

Resources map to URLs

URLs shouldn’t change -> broken links.

Wednesday, 3 April 13

Page 9: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

Example 1: Blog post

A simple rails Blog app, with a “Post” model.

Example JSON response:

Demo...

Wednesday, 3 April 13

Page 10: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

Example 2: Meetup API

GET https://api.meetup.com/2/event/106662252.json

How do we access the group?

Wednesday, 3 April 13

Page 11: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

Example 2: Meetup API Docs

Bookmark this: http://www.meetup.com/meetup_api/docs/

App needs to know how to build URLs -> hard coded.

GET https://api.meetup.com/2/groups?group_id={id}

Data is not very descriptive of the API.

Wednesday, 3 April 13

Page 12: RESTful Hypermedia APIs April... · Pros and Cons of REST Pros: Cacheable, Distributable / Routable, Compatibility, Less bandwidth, Simpler for clients, Freedom of media types. Cons:

HAL: Hypertext Application Language

http://stateless.co/hal_specification.htmlImplementations for Objective-C, Ruby, PHP, C#, Java, etcRicher JSON (or XML) structure, eg:{ "_links": { "self": { "href": "http://example.com/" } }}

Wednesday, 3 April 13