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

RESTful APIs

RESTful APIs

A brief introduction to RESTful APIs concept.

Enderson Tadeu S. Maia

December 17, 2014
Tweet

More Decks by Enderson Tadeu S. Maia

Other Decks in Programming

Transcript

  1. 30 minutes to • REST • Constraints • Richard Maturity

    Model (RMM) • HTTP Methods • HTTP Satus Codes • Resource Naming • Format • Linking • …
  2. Uniform interface • Resource-Based • Manipulation of Resources Through Representations

    • Self-descriptive Messages • Hypermedia as the Engine of Application State (HATEOAS)
  3. Level 0 The swamp of POX $ curl -X POST

    -d \
 "<?xml version=“1.0"?> \
 <methodCall> \
 <methodName>examples.getStateName</methodName> \
 <params> \
 <param> \
 <value><i4>40</i4></value> \
 </param> \ </params> \
 </methodCall>" http://api.example.com
  4. Level 2 HTTP Verbs • GET - http://host/users • PUT

    - http://host/users • DELETE - http://host/users
  5. GET

  6. PUT

  7. 2XX

  8. 2XX • 200 - OK • 201 - Created •

    202 - Accepted • 204 - No Content
  9. 3XX

  10. 4XX

  11. 4XX • 400 - Bad Request • 401 - Unauthorized

    • 403 - Forbidden • 404 - Not Found • 409 - Conflict
  12. 5XX

  13. Verbs • POST - to create (INSERT) a new resource

    • GET - to recover (SELECT) a specific resource • PUT/PATCH - to UPDATE a specific resource • DELETE - to DELETE a specific resource
  14. Resource Naming • POST http://example.com/customers • GET http://example.com/customers/33245 • GET|PUT|DELETE

    http://example.com/products/66432 • GET http://example.com/customers/33245/orders • POST http://example.com/customers/33245/orders/ 8769/lineitems • GET http://example.com/customers/33245/orders/ 8769/lineitems/1

  15. Resource Naming Anti-Pattern • GET http://api.example.com/services? op=update_customer&id=12345&format=json • GET http://api.example.com/

    update_customer/12345 • GET http://api.example.com/customers/ 12345/update • PUT http://api.example.com/customers/ 12345/update
  16. What’s missing ? • More about HTTP Header • HTTP

    Authentication samples • Using Tokens • Versioning strategies • ?
  17. References • http://stateless.co/hal_specification.html • http://jsonapi.org • http://www.infoq.com/articles/Web-APIs-From-Start-to-Finish • http://restfulwebapis.com •

    http://www.restapitutorial.com • http://martinfowler.com/articles/richardsonMaturityModel.html • http://restcookbook.com • http://www.w3.org/TR/json-ld/ • http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm • http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven • http://brockallen.com/2012/05/14/http-status-codes-for-rest/