Demystifying REST - SFRails meetup

2,853 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,853
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Demystifying REST - SFRails meetup

  1. 1. Demystifying REST Kirsten Jones, API Ninja, 3Scale
  2. 2. 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
  3. 3. Kirsten Jones - @synedra This talk  HTTP - Quick Overview  REST Web Services  Debugging Tips and Techniques
  4. 4. 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
  5. 5. 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
  6. 6. Kirsten Jones - @synedra How does HTTP Work?  Client sends a request  Method  URL  Headers  Parameters  Body  Server replies with a response  Content  Status  Headers
  7. 7. 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
  8. 8. 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;
  9. 9. 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
  10. 10. Kirsten Jones - @synedra Example: HTTPScoop Request
  11. 11. Kirsten Jones - @synedra Example: HTTPScoop Headers
  12. 12. Kirsten Jones - @synedra Example: HTTPScoop Request/Response
  13. 13. 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
  14. 14. 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
  15. 15. Kirsten Jones - @synedra Example Request:
  16. 16. Kirsten Jones - @synedra Example Request:  Headers
  17. 17. Kirsten Jones - @synedra Example Request:  Request/Response
  18. 18. Kirsten Jones - @synedra Example REST Response Status: 200 Content: {"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}}}
  19. 19. 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
  20. 20. Kirsten Jones - @synedra PreventingPreventableProblems  Use existing libraries/code/examples  Code Defensively  Test Defensively  Test Frequently  Handle Errors Gracefully  Pass back errors/log issues 20
  21. 21. Kirsten Jones - @synedra Questions? Information about me:  @synedra on twitter  kirsten@3scale.net  http://www.princesspolymath.com  API Strategy Conference (Oct. 23-25) Thanks to Twilio!!! 21

×