Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tom Marrs: Restful API Design At Work

Tom Marrs: Restful API Design At Work

Tom's Slides from the June 4th, 2013 Denver Open Source Users' Group Meeting: Restful API Design At Work

Dan Hillenbrand

June 04, 2013
Tweet

Other Decks in Technology

Transcript

  1. Our Case Study - Mentoring Program A Relationship 6 meetings

    Face-to-face or Phone Mentoring Checklist Friday, May 10, 13
  2. Discover Resources Type Example Things Order, Member, Product Associations Enrollment,

    Membership, Marriage, Employment Processes Onboarding, Underwriting, Mentoring Functions Driving Directions, Search Friday, May 10, 13
  3. Uniform Interface - HTTP Methods/Verbs HTTP Verb/ Method Action GET

    Read POST Create [Update] PUT Update [Create] DELETE Delete Friday, May 10, 13
  4. HTTP Status Codes - Typical HTTP Verb/ Method HTTP Status

    Code Meaning GET 200 OK GET 404 Not Found POST 201 Created PUT 200 OK PUT 404 Not Found PUT 409 Conflict DELETE 200 OK DELETE 404 Not Found DELETE 409 Conflict Friday, May 10, 13
  5. HTTP Status Codes - Other HTTP Verb/ Method HTTP Status

    Code Meaning POST / PUT / DELETE 202 Accepted - Process request later POST / PUT / DELETE 204 No Content GET / PUT / DELETE 301 Moved Permanently ALL 400 Bad Request ALL 401 Unauthorized ALL 500 Internal Server Error Friday, May 10, 13
  6. Verbs - Really Bad! /listPairs /reviewPairStatus /deletePair /updateProgress ... /getAvgWaitTimeForMember

    - Really?? /provideMemberFeedback /provideMentorFeedback Friday, May 10, 13
  7. Our URIs http://mentoring.simplytoast.org/ URI Description Method pairs List all Pairs

    GET pairs/completed List all Completed Pairs GET pairs/2010/Q4 List all Pairs in Period GET pairs/{pairId} Review Pair Status GET pairs/{pairId} Update Pair Status PUT pairs/{pairId}/mentors/ {mentorId} Update progress PUT Friday, May 10, 13
  8. Our URIs ... Cont’d URI Description Method pairs/{pairId} Assign Mentor

    POST pairs/{pairId} Delete Pair DELETE members List all Members in Program GET members/unassigned List all unassigned Members GET members/avg-wait Get average wait time GET members Add Member (register) POST Friday, May 10, 13
  9. Our URIs ... Cont’d URI Description Method members/{memberId} Delete Member

    DELETE members/{memberId}/ feedback Get Feedback by Member GET members/{memberId}/ feedback Provide Feedback POST mentors List all Mentors GET mentors/available List all available Mentors GET mentors/{mentorId} Update Mentor PUT Friday, May 10, 13
  10. Our URIs ... Cont’d URI Description Method mentors Add Mentor

    (register) POST mentors/{mentorId} Delete Mentor DELETE Friday, May 10, 13
  11. Use Parameters - Simplify Associations Before (Update Progress) /pairs/{pairId}/mentor/{mentorId} After

    (Update Progress) /pairs/{pairId}?mentor={mentorId} Friday, May 10, 13
  12. Versioning ... Cont’d Change Don’t Change Deleted / Renamed Resources

    New Resources Removed HTTP Methods New HTTP Methods Different Data (same URI) New Data Formats New Attributes / Data Elements Friday, May 10, 13
  13. Content Negotiation Format HTTP Request JSON Accept Header - application/json

    simplytoast.api/members/243.json XML Accept Header - application/xml simplytoast.api/members/243.xml Friday, May 10, 13
  14. Dyson Demo dyson init members cd members npm install dyson-image

    --save-dev npm install dyson-generators --save-dev cd .. (back to projects directory) dyson members http://localhost:3000/members/1 http://localhost:3000/members Friday, May 10, 13
  15. RESTful API Resources Teach a Dog to REST - http://blog.apigee.com/detail/restful_api_design/

    Apigee API Best Practices - http://blog.apigee.com/taglist/restful rapi_doc - http://blogs.burnsidedigital.com/2011/12/generating-api- documentation-with-rapi_doc/ RESTdoclet - https://github.com/IG-Group/RESTdoclet API Evangelist - http://apievangelist.com/ The Programmable Web (API Directory) - http:// www.programmableweb.com/apis Stormpath - http://www.stormpath.com/blog/designing-rest-json-apis Friday, May 10, 13