Rails and Resources Bart Zonneveld
May 26, 2015
Rails and Resources
Bart Zonneveld
Bart!Programmer
DeanDesigner
Sjoerd!Programmer
Niels!Project Lead
http://madebyhiro.com
± 600.000 visitors / day !
± 700.000 videos / day
± 4.000 req / min (10k peak) !
230 ms avg response
Uitzending Gemist
Amazon.com!Let’s buy a book about Ruby on Rails
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book • Put the book in my cart
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book • Put the book in my cart • Get the list of all books
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book • Put the book in my cart • Get the list of all books • Get a specific book
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book • Put the book in my cart • Get the list of all books • Get a specific book
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book • Put the book in my cart • Get the list of all books • Get a specific book • Put the book in my cart
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book • Put the book in my cart • Get the list of all books • Get a specific book • Put the book in my cart • Get the contents of my cart
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book • Put the book in my cart • Get the list of all books • Get a specific book • Put the book in my cart • Get the contents of my cart • Delete a book from my cart
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book • Put the book in my cart • Get the list of all books • Get a specific book • Put the book in my cart • Get the contents of my cart • Delete a book from my cart • Post money to Amazon
Amazon.com!Let’s buy a book about Ruby on Rails
• Get a list of all books • Get a specific book • Put the book in my cart • Get the list of all books • Get a specific book • Put the book in my cart • Get the contents of my cart • Delete a book from my cart • Post money to Amazon
Amazon.com!Let’s buy a book about Ruby on Rails
Verb Noun
GET books
PUT cart
DELETE book
POST money
Amazon books
Books! ! ! ! ! /books!
! Best sellers /books/best_sellers!
! Hardcover /books/hardcover
Sale /books/sale
Top rated /books/top_rated
Top rated books!/books/top_rated
Top rated books!/books/top_rated.json
!{ 'books' : [ ... { id: '3487', title: 'Agile Web Development with Rails 4', authors: [ 'Sam Ruby', 'Dave Thomas', 'David Heinemeier Hansson' ], price: '$ 26.37', rating: '4.2' } ... ]}
Top rated books!/books/3487.json
!{ id: '3487', title: 'Agile Web Development with Rails 4', authors: [ 'Sam Ruby', 'Dave Thomas', 'David Heinemeier Hansson' ], price: '$ 26.37', rating: '4.2'}
Amazon.rb
!
Amazon.routes do resources :books end
Amazon.rb!
Amazon.routes do resources :books do collection :top_rated end end
Amazon.rb
Prefix Verb URI Pattern Controller#Action
books GET /books books#index
top_rated_books GET /books/top_rated books#top_rated
POST /books books#create
new_book GET /books/new books#new
edit_book GET /books/:id/edit books#edit
book GET /books/:id books#show
PUT /books/:id books#update
DELETE /books/:id books#destroy
Amazon.routes do resources :books do collection :top_rated end end
Amazon.rb
Prefix Verb URI Pattern Controller#Action
books GET /books books#index
top_rated_books GET /books/top_rated books#top_rated
POST /books books#create
new_book GET /books/new books#new
edit_book GET /books/:id/edit books#edit
book GET /books/:id books#show
PUT /books/:id books#update
DELETE /books/:id books#destroy
Amazon.routes do resources :books do collection :top_rated end end
REpresentational State Transfer
Roy Fielding
Architectural Styles and the Design of Network-based Software Architectures (2000)
REpresentational State Transfer
“How I Explained REST to My Wife” Ryan Tomayko
tiny.cc/rest_rails