Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

REST, RESTful API

4,656 views

Published on

Published in: Software, Technology

REST, RESTful API

  1. 1. REST, RESTful API
  2. 2. API
  3. 3. Developers as Customers
  4. 4. Make APIs Easy to Learn
  5. 5. Design APIs Well
  6. 6. Bad designed APIs ...
  7. 7. /getUser /getAllUsers /findUser /findUserAccounts /deleteUser /changeUserPass ...
  8. 8. API Consumers
  9. 9. API Designers
  10. 10. Simplicity
  11. 11. REST is your friend
  12. 12. Base URLs per each resource
  13. 13. Collection /users
  14. 14. Entity /users/hossein /users/13246
  15. 15. HTTP Verbs
  16. 16. POST GET PUT DELETE PATCH ...
  17. 17. C.R.U.D. Operations
  18. 18. C. POST
  19. 19. R. GET
  20. 20. U. PUT
  21. 21. D. DELETE
  22. 22. PUT is also used for creating
  23. 23. PATH for partial updates
  24. 24. Verb Resource POST GET PUT DELETE /users New User List Users ? Delete Everybody /users/hossein ? Show Hossein :) Update / Create Hossein Delete Hossein :(
  25. 25. Resources as Nouns
  26. 26. Plural Nouns
  27. 27. Stop using Verbs
  28. 28. Verb Resource POST GET PUT DELETE /users New User List Users ? Delete Everybody /users/hossein ? Show Hossein :) Update / Create Hossein Delete Hossein :(
  29. 29. Associations
  30. 30. Chaining resources together
  31. 31. Chaining resources together /users/hossein/accounts
  32. 32. Nesting too much
  33. 33. Complexitymay arise
  34. 34. Keep Base URL Simple
  35. 35. ? Query String
  36. 36. ? Query String /users?state=pending
  37. 37. Params in Headers
  38. 38. Pagination
  39. 39. Offset / Limit
  40. 40. Page number
  41. 41. Start / Count
  42. 42. HATEOAS
  43. 43. Hypermedia As The Engine Of Application State
  44. 44. GET /account/12345 HTTP/1.1 HTTP/1.1 200 OK <?xml version="1.0"?> <account> <account_number>12345</account_number> <balance currency="usd">100.00</balance> <link rel="deposit" href="/account/12345/deposit" /> <link rel="withdraw" href="/account/12345/withdraw" /> <link rel="transfer" href="/account/12345/transfer" /> <link rel="close" href="/account/12345/close" /> </account>
  45. 45. GET /account/12345 HTTP/1.1 HTTP/1.1 200 OK <?xml version="1.0"?> <account> <account_number>12345</account_number> <balance currency="usd">-30.00</balance> <link rel="deposit" href="/account/12345/deposit" /> </account>
  46. 46. Versioning
  47. 47. Date /2014-04-05/...
  48. 48. Decimal Point /v1.0/...
  49. 49. In Query String …?v=1
  50. 50. Integer :) /v1/ /v2/
  51. 51. Leftmost in the URI
  52. 52. Header
  53. 53. Be Explicit
  54. 54. Limiting Entity Fields
  55. 55. Limiting Entity Fields /users:(id,first-name)
  56. 56. Limiting Entity Fields /users?fields=id,first-name
  57. 57. Formats (JSON, XML)
  58. 58. Header Content-Type: application/json
  59. 59. Extension /users.json
  60. 60. Query String /users?type=json
  61. 61. Error Handling
  62. 62. HTTP Status Codes
  63. 63. Error Messages
  64. 64. Linking to comprehensive explanation
  65. 65. Domain
  66. 66. Domain api.example.com
  67. 67. Domain dev.example.com
  68. 68. Domain example.com/api/

×