Consumindo APIs REST com Ruby

887 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
887
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Consumindo APIs REST com Ruby

  1. 1. Consumindo APIs REST com Ruby Guilherme Cavalcanti Líder técnico, plataforma de aplicativos Thursday, 31 January 13
  2. 2. REST Thursday, 31 January 13
  3. 3. Relembrando: REST • Define a comunicação em sistemas distribuidos • Padrões utilizados na comunicação Thursday, 31 January 13
  4. 4. REST is about • Recursos • Representações • Interface uniforme • Hypermedia Thursday, 31 January 13
  5. 5. Recurso • São as entidades do sistema • Usuário, Matrícula, Aula, Post, etc. • Conceito abstrato • Recurso != Representação • Um recurso pode ser representado de diversas formas Thursday, 31 January 13
  6. 6. Recurso { "id": 4, "login": "guiocavalcanti", "first_name": "Guilherme", "last_name": "Cavalcanti", "birth_localization": "Recife, Brasil", "friends_count": 175, "localization": "Recife, Brasil", "email": "guilhermec@redu.com.br", "social_networks": [ { "name": "linkedin", "profile": "http://br.linkedin.com/in/guiocavalcanti" }, { "name": "twitter", "profile": "http://www.twitter.com/guiocavalcanti" } ], "thumbnails": [ { "size": "32x32", GET /api/me HTTP/1.1 Thursday, 31 January 13
  7. 7. Interface uniforme • As ações para operar um recurso são as mesmas • criar um Post no mural • criar um Disciplina Thursday, 31 January 13
  8. 8. Interface uniforme POST /api/users/4/statuses HTTP/1.1 Host: redu.com.br Connection: keep-alive Cache-Control: no-cache Pragma: no-cache Accept: application/json Authorization: OAuth XXX Content-Type: application/json { "status" : { "text" : "API 101" } } Thursday, 31 January 13
  9. 9. Interface uniforme POST /api/courses/19/spaces HTTP/1.1 Host: redu.com.br Connection: keep-alive Cache-Control: no-cache Pragma: no-cache Accept: application/json Authorization: OAuth XXX Content-Type: application/json { "space" : { "name" : "Minha Disciplina" } } Thursday, 31 January 13
  10. 10. Hypermedia • Uma API REST deve se comportar como uma página web • Cada página contém referências para outras páginas que são importantes naquele contexto Thursday, 31 January 13
  11. 11. Hypermedia "links": [ { "href": "http://www.redu.com.br/api/users/guiocavalcanti/statuses/timeline", "rel": "timeline" }, { "href": "http://www.redu.com.br/api/users/guiocavalcanti/contacts", "rel": "contacts" }, { "href": "http://www.redu.com.br/api/users/guiocavalcanti/statuses", "rel": "statuses" }, { "href": "http://www.redu.com.br/api/users/guiocavalcanti/chats", "rel": "chats" }, { "href": "http://www.redu.com.br/api/users/guiocavalcanti/enrollments", "rel": "enrollments" }, { GET /api/me HTTP/1.1 Thursday, 31 January 13
  12. 12. Hands on Thursday, 31 January 13
  13. 13. OAuth Thursday, 31 January 13
  14. 14. OAuth 2.0 • Dono do recurso • Aplicação terceira • Servidor de autenticação • Servidor de recursos Thursday, 31 January 13
  15. 15. Para uma aplicação Web Thursday, 31 January 13
  16. 16. Hands on Thursday, 31 January 13
  17. 17. Instalação Thursday, 31 January 13
  18. 18. Instalando no Windows http://railsinstaller.org/ Thursday, 31 January 13
  19. 19. Instalando no Linux/Mac $ curl -L https://get.rvm.io | bash -s stable --ruby https://rvm.io/ http://railscasts.com/episodes/200-rails-3-beta-and-rvm Thursday, 31 January 13
  20. 20. OAuth 2 com Ruby Thursday, 31 January 13
  21. 21. OAuth 2.0 https://github.com/intridea/oauth2 Thursday, 31 January 13
  22. 22. HTTP com Ruby Thursday, 31 January 13
  23. 23. OAuth 2.0 https://github.com/lostisland/faraday Thursday, 31 January 13
  24. 24. Gerenciamento de dependências http://gembundler.com/ $ gem install bundler Thursday, 31 January 13

×