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.

RailsスタイルからRESTを学ぼう よちがや.rb

797 views

Published on

よちよち.rb & Sendagaya.rb 合同開催「よちがや.rb」
https://yochiyochirb.doorkeeper.jp/events/83343

Published in: Technology
  • Be the first to comment

RailsスタイルからRESTを学ぼう よちがや.rb

  1. 1. Rails 
 REST 2019.01.07 .rb & Sendagaya.rb .rb
  2. 2. @tkawa • (Toru Kawamura) • REST (RESTafarian) • Sendagaya.rb (w/ @fukajun) • “RESTful Web APIs” 
 (2016)
  3. 3. • REST • Web URL, HTTP • Rails • REST •
  4. 4. – Rails 2 2.2 Rails “REST” REpresentational State Transfer REST Web 
 1
  5. 5. Wikipedia … REST 2 • REST Web •  (RPC) XML + HTTP SOAP REST 2 https://ja.wikipedia.org/wiki/Representational_State_Transfer
  6. 6. REST • Web ‣ Web Web Web API REST Web – Web 3 3.2
  7. 7. REST • Web (URL, HTTP, HTML) • URL • ( ) • curl HTTP • • 4 (CRUD) Web 
 REST …
  8. 8. 
 
 REST 
 
 [ ] REST
  9. 9. 
 
 REST 
 
 [ ] URL HTTP HTML JavaScriptWeb
  10. 10. 
 
 REST 
 
 [ ] HTTP GraphQL / JSON URL?
  11. 11. REST 
 Web • URL, HTTP, HTML
  12. 12. 
 
 REST 
 
 [ ] URL HTTP HTTP URL
  13. 13. Web 1. 2. 1. Web 2. (HTML, CSS, JavaScript, JPEG,...)
  14. 14. • URL • •
  15. 15. Web 1. 2. 1. Web 2. (HTML, CSS, JavaScript, JPEG,...) URL,
  16. 16. Web 1. 2.
  17. 17. URL • Web 
 • • https://twitter.com/tkawa https://yochiyochirb.doorkeeper.jp/events/83343
  18. 18. .rb wiki
  19. 19. .rb wiki GitHub yochiyochirb meetups Wiki New Page
  20. 20. .rb wiki https://github.com/yochiyochirb/meetups/wiki/_new
  21. 21. POST https://github.com/yochiyochirb/meetups/wiki
  22. 22. GET POST PUT DELETE 4 !! ※Create, Read, Update, Delete CRUD
  23. 23. GET https://github.com/yochiyochirb/meetups/wiki
 POST https://github.com/yochiyochirb/meetups/wiki
 PUT https://github.com/yochiyochirb/meetups/wiki
 DELETE https://github.com/yochiyochirb/meetups/wiki URL
  24. 24. GET POST PUT DELETE
  25. 25. GET http://example.com/users/show/123 POST http://example.com/users/create
  26. 26. GET http://example.com/users/show/123 POST http://example.com/users/create POST http://example.com/users/show/123 GET http://example.com/users/create ❌
  27. 27. GET http://example.com/users/show/123 POST http://example.com/users/create ⭕ GET http://example.com/users/123 ⭕ POST http://example.com/users
  28. 28. • Web • • 3
  29. 29. • 200 : • 200 OK • 300 : URL • 301 Moved Permanently • 400 : • 404 Not Found • 500 : • 500 Internal Server Error
  30. 30. REST 
 Web • URL, HTTP, HTML • •
  31. 31. Rails • REST 
 • • Rails
  32. 32. GET http://example.com/users/show/123 POST http://example.com/users/create GET http://example.com/users/123 POST http://example.com/users
  33. 33. GET POST PUT DELETE /user
  34. 34. http://d.hatena.ne.jp/tkawa/20140923 http://d.hatena.ne.jp/tkawa/20140923/p1 http://baseball.example.jp/leagues http://baseball.example.jp/leagues/central http://railsapp.example.com/users http://railsapp.example.com/users/123
  35. 35. http://d.hatena.ne.jp/tkawa/20140923 http://d.hatena.ne.jp/tkawa/20140923/p1 http://baseball.example.jp/leagues http://baseball.example.jp/leagues/central http://railsapp.example.com/users http://railsapp.example.com/users/123 / / ,,
  36. 36. GET POST PUT DELETE /users /users/123
  37. 37. GET POST PUT DELETE /users index create - - /users/123 show - update destroy GET /users/new → new ( )
 GET /users/123/edit → edit ( ) UsersController
  38. 38. 
 “resources” • 
 • users, groups, … resources :users resources :groups
  39. 39. GET POST PUT DELETE /users index create - - /users/123 show - update destroy / /
  40. 40. GET POST PUT DELETE /groups index create - - /groups/1 show - update destroy Q.
  41. 41. 
 
 membership GET POST PUT DELETE /memberships index create - - /memberships/1 show - update destroy resources :memberships
  42. 42. REST
  43. 43. REST • Web ‣ REST • Web ‣ Web
  44. 44. REST Web 
 Web REST
  45. 45. 
 https://ja.wikipedia.org/wiki/
  46. 46. Rails MVC 
 • Rails app/ models views controllers 3 Rails MVC (model-view-controller)  Model-View-Controller (MVC) – Rails 1 1.3.3
  47. 47. • (Granularity) • ( ) – Web 1 3.2
  48. 48. REST Roy Fielding • 1995 Apache HTTP Server Apache HTTP Server • 1996 5 HTTP/1.0 (RFC 1945) • 1997 1 HTTP/1.1 (RFC 2068) • 2000 “Architectural Styles and the Design of Network-based Software Architectures” 
 Web REST
  49. 49. REST 
 • • • • • [ ] • ‣ ‣ ‣ ‣
  50. 50. REST(Web) • ‣ Web 
 • ‣ Web • ‣ • ‣ Web
  51. 51. • REST • Web URL, HTTP, HTML • 3 • URL • • • 
 Rails http://rest-pattern.hatenablog.com/ http://d.hatena.ne.jp/tkawa/searchdiary?word=*[rest]
  52. 52. Q • Rails PUT PATCH • Web Web API
  53. 53. GET POST PUT
 PATCH DELETE ❌
  54. 54. Web Web API
  55. 55. 
 
 REST 
 
 [ ] URL HTTP JSONWeb API
  56. 56. 
 
 REST 
 
 [ ] HTTP GraphQL / JSON GraphQL URL? REST REST
  57. 57. Web API REST 
 • ‣ Web 
 • ‣ Web • ‣ • ‣ Web
  58. 58. … •

×