What is REST?
Why is it part of the rails way?
javier ramirez
@supercoco9
20 years ago
15 years ago
the web of portals
sharing via widgets
Screen
Scrapping
SOAP
Services
mashups and
integrated
services
https://api.github.com/users/javier
REST
saved
the
web
REST is an
architecture
for the web
Roy Fielding's PHD Dissertation.
2000
REST & RAILS
Rails
saved the
web
Client – server
Stateless
Cacheable
Multi-layered
REST constraints. HTTP basics
uniform
interface*
REST constraints. The good parts
* Convention over configuration FTW
resources
representations
metadata
uniform interface. Elements
resource:
Anything that
can be named
uniform interface
resource identifiers:
URI
uniform interface
https://api.teowaki.com/teams/teowaki-community
https://api.teowaki.com/teams/fosdem-2014
https://api.teowaki.com/users/javier
http://localhost:3000/posts/1
representations
standard formats/mime-types
uniform interface
uniform interface: representations. HTML
uniform interface: representations. JSON
REpresentational
State
Transfer
GET
POST
PUT/PATCH
DELETE
uniform interface: transfer
uniform interface: transfer. GET (no id)
uniform interface: transfer. POST (no id)
uniform interface: transfer. GET (with id)
uniform interface: transfer. DELETE (with id)
HTTP as usual +
resources
representations
metadata
So REST is basically
Routes:
resources,member,collection
Controller:
respond_to,format,status,headers
Views:
show.html.erb, show.json.jbuilder
Rest in Rails
Rest in Rails: basic routes
Rest in Rails: advanced routes
Rest in Rails: advanced routes
Rest in Rails: members and collections
tips on routes: don't overload
GET /users/1-javier/messages
get :messages on: :member
tips on routes: don't overload
GET /users/1-javier/messages
POST /users/1-javier/messages
get :messages on: :member
post :messages on: :member
tips on routes: don't overload
GET /users/1-javier/messages
POST /users/1-javier/messages
members? No.
Naming is hard.
But very
important
tips on routes
Resources are not models
Don't expose your implementation details
tips on routes
Easier to understand
Change the internals
without breaking the
contract
Resources based on
business objects are
more resistant to
versioning
More opacity means
more security
Rest in Rails: controllers. Basic
actions
respond_to & format
Rest in Rails: controllers
huddle
200 OK
201 Created
202 Accepted
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
410 Gone
twitter
200 OK Success!
304 Not Modified
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
406 Not Acceptable
420 Enhance Your Calm
500 Internal Server Error
502 Bad Gateway
503 Service Unavailable
Useful Status
429 Too many requests
204 No Content
teowaki
200 OK Success!
201 Created
304 Not Modified
401 Unauthorized
403 Forbidden
404 Not Found
422 Unprocessable Entity
406 Not Acceptable
500 Internal Server Error
Rest in Rails: controllers. headers
representations
Rest in Rails: views. templates
But I'm not
building an API.
Do I need REST?
Hypermedia
Navigable APIs
API pagination
API links
------
Next
steps
Several resources in a single request
API/Hypermedia Ruby gems
https://github.com/rails-api/rails-api
https://github.com/intridea/grape
https://github.com/apotonick/roar
RESTful web service/application
client-server,stateless,layered,cacheable
Resources
Resource Identifiers
Uniform interface
operations
Representations
Metadata
Hypermedia
Find related links at:
https://teowaki.com/teams/javier-community/link-categories/rest
Thank you
Javier Ramírez
@supercoco9
https://airpair.me/javier
teowaki is the place to share
links, best practices,
documentation, gossip and
lifehacks with other developers.

What is rest. Why is it part of the Rails way?. Railsconf 2014. Javier Ramirez