Demystifying REST - SFRails meetup

21
Demystifying REST Kirsten Jones, API Ninja, 3Scale

Transcript of Demystifying REST - SFRails meetup

Page 1: Demystifying REST - SFRails meetup

Demystifying RESTKirsten Jones, API Ninja, 3Scale

Page 2: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

API Ninja (that’s me!)

Developer Evangelist Worked at Netflix, LinkedIn Lots of experience helping developers Language Polyglot

Where I came from...

2

Page 3: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

This talk

HTTP - Quick Overview REST Web Services Debugging Tips and Techniques

Page 4: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Want to play along?

HTTPScoop Macintosh only Pretty (my favorite) Doesn’t support SSL http://www.tuffcode.com

Fiddler Windows only Supports SSL http://fiddler2.com

4

Page 5: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

HTTP

HyperText Transfer Protocol Used for conversations between web

clients and servers Supports verbs for GET, PUT, POST,

DELETE Includes support for query parameters

Page 6: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

How does HTTP Work?

Client sends a request Method URL Headers Parameters Body

Server replies with a response Content Status Headers

Page 7: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

What do you Mean, Status?

HTTP response codes for dummies. 50x: we f*cked up. 40x: you f*cked up. 30x: ask that dude over there. 20x: cool.

Props to @DanaDanger for that one

Page 8: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

An example request

Chrome browser sends a request to Google Method: GET URL: http://www.google.com Headers:▪ Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/

*;q=0.8▪ Accept-Language: en-US,en;q=0.8▪ Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3▪ Connection: keep-alive▪ User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3)

AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19

▪ Accept-Encoding: gzip,deflate,sdch▪ Cookie:

NID=59=EudJ2a15ql8832PCysQA0qchtuvGWMoA7rkp79VpIYAQ8-j42IO17LFudCYNMXm9l6SHcu3YgrGRCdrRCyM468xPZaOek4Pi-AXQ8eARqU1SGYx6y7_9LW-c3HHb-vs2;

Page 9: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Example Response Google sends a response

Headers:▪ Content-Length: 24716▪ Content-Encoding: gzip▪ Set-Cookie: NID=59=F48kbwfwOi-qCHJyrnMSUlDBVxK-

ZVKZpq5B5jttt_25IRN4lS-0rQcVttq-dnOIlQzafw1i4HPQAO0RpZ7NuC0WCKWta7SYoekx0--YGf2zIFZ9VXIKS-_UEaOH9iBe; expires=Sat, 10-Nov-2012 21:26:46 GMT; path=/; domain=.google.com; HttpOnly

▪ Expires: -1▪ Server: gws▪ X-XSS-Protection: 1; mode=block▪ Cache-Control: private, max-age=0▪ X-Frame-Options: SAMEORIGIN▪ Content-Type: text/html; charset=UTF-8▪ Date: Fri, 11 May 2012 21:26:46 GMT

Content: A bunch of HTML Status: 200

Page 10: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Example: HTTPScoop

Request

Page 11: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Example: HTTPScoop

Headers

Page 12: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Example: HTTPScoop

Request/Response

Page 13: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

REST APIs Leverage HTTP

Uses URL paths to define resources Create, Read, Update, Delete

POST, GET, PUT, DELETE Error Codes

HTTP Status Codes Request parameters

Query parameters Response types and configuration

Headers

Page 14: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Example REST Request

Blog Info from Tumblr GET (read) http://api.tumblr.com/v2/

blog/synedra.tumbler.com/info Requires api_key sent as parameter

Page 15: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Example Request:

Page 16: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Example Request:

Headers

Page 17: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Example Request:

Request/Response

Page 18: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Example REST Response

Status: 200Content:

{"meta": {"status":200, "msg":"OK” }, "response":{ "blog":{"title":"Untitled","posts":0, "name":"synedra", "url":"http:\/\/synedra.tumblr.com\/", "updated":0, "description":"","ask":false,"likes":0}}}

Page 19: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Troubleshooting API Calls

HTTPScoop to understand your calls Compare against a known good call Simplify request (weird chars?) Try a different (simpler) resource Ask good questions

19

Page 20: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Preventing Preventable Problems

Use existing libraries/code/examples Code Defensively Test Defensively Test Frequently Handle Errors Gracefully

Pass back errors/log issues

20

Page 21: Demystifying REST - SFRails meetup

Kirsten Jones - @synedra

Questions?

Information about me: @synedra on twitter [email protected] http://www.princesspolymath.com API Strategy Conference (Oct. 23-25)

Thanks to Twilio!!!

21