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

REST: Definições e Boas Práticas

REST: Definições e Boas Práticas

Apresentação realizada como parte da iniciativa VTEX Tech Talks.
--
Presentation made as a part of the VTEX Tech Talks initiative.

Alex Tercete

March 18, 2014
Tweet

More Decks by Alex Tercete

Other Decks in Programming

Transcript

  1. HTTP/1.1 200 OK Cache-Control: private, max-age=300 Expires: Tue, 18 Mar

    2014 19:00:00 GMT ETag: 50780f47f6839d47d60bc4555ee00c3f GET /dogs HTTP/1.1
  2. HTTP/1.1 304 Not Modified Cache-Control: private, max-age=300 Expires: Tue, 18

    Mar 2014 19:00:00 GMT ETag: 50780f47f6839d47d60bc4555ee00c3f GET /dogs HTTP/1.1 If-None-Match: 50780f47f6839d47d60bc4555ee00c3f
  3. GET /v1/dogs HTTP/1.1 GET /dogs HTTP/1.1 X-VTEX-Zoo-Version: v1 GET /dogs

    HTTP/1.1 Accept: application/vnd.vtex.zoo-v1+json Rota Cabeçalho Proprietário Cabeçalho Padrão
  4. GET /dogs HTTP/1.1 Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== GET /dogs HTTP/1.1 Authorization:

    AWS AKIAIOSFODNN7EXAMPLE:fr...Dzg= GET /dogs HTTP/1.1 X-VTEX-Api-AppKey: some-key X-VTEX-Api-AppToken: 5Om3tOkE|\| Padrão Proprietária Muito Proprietária
  5. HTTP/1.1 401 Unauthorized WWW-Authenticate: Basic Content-Type: application/json { “errorCode”: “auth.invalid_credentials”,

    “message”: “Credenciais inválidas”, “help”: “http://docs.vtex.com/api/authentication” }
  6. HTTP/1.1 400 Bad Request Content-Type: application/json { “errorCode”: “checkout.invalid_order”, “message”:

    “Dados do pedido inválidos”, “reasons”: { “id”: “É obrigatório” } }
  7. HTTP/1.1 200 OK Content-Type: application/json { “name”: “Snoopy” “owners”: [{

    “name”: “Charlie Brown” }] } GET /dogs/Snoopy HTTP/1.1 Accept: application/json
  8. HTTP/1.1 200 OK Content-Type: application/json { “name”: “Snoopy”, “owners”: {

    “href”: “/dogs/Snoopy/owners” } } GET /dogs/Snoopy HTTP/1.1 Accept: application/json
  9. Resumo • REST = HTML + Recursos • Verbos, não!

    Substantivos, sim! • Status Codes: – 20[014], 30[124], 4(0[13459]|2[29]), 50[03] • Cache • Versionamento: – Accept • Autenticação: – OAuth 2.0 • Hypermedia: – href • Virtualização
  10. Referências • http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm • Apigee – https://blog.apigee.com/detail/restful_api_design_nouns_are_good_verbs_are_bad – https://blog.apigee.com/detail/restful_api_design_plural_nouns_and_concrete_name s

    – https://blog.apigee.com/detail/simplify_associations_sweep_complexities_under_the _http – https://blog.apigee.com/detail/restful_api_design_what_about_errors – https://blog.apigee.com/detail/restful_api_design_chatty_apis – https://blog.apigee.com/detail/restful_api_design_complement_with_sdk – https://blog.apigee.com/detail/restful_api_design_api_virtualization
  11. Referências (2) • http://blogs.burnsidedigital.com/2013/07/whats-a-rest-api/ • Steve Klabnik – http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or- http

    – http://blog.steveklabnik.com/posts/2011-08-07-some-people-understand- rest-and-http – http://blog.steveklabnik.com/posts/2012-02-23-rest-is-over – http://blog.steveklabnik.com/posts/2012-02-13-an-api-ontology – http://timelessrepo.com/haters-gonna-hateoas • http://barelyenough.org/blog/2008/05/versioning-rest-web-services/ • http://www.mobify.com/blog/beginners-guide-to-http-cache-headers/