2. Overview
• WTF is REST?
• Sinatra and Ruby
• Case Study (0_0)
• Q &A
3. WTF is REST?
• Created in 2000 by Roy Fielding
in his doctoral dissertation
• Representational state transfer
• WWW is largest
implementation of REST
4. Ummm...
The key abstraction of information in REST is a
resource. Any information that can be named
can be a resource: a document or image, a
temporal service (e.g. “today’s weather in Los
Angeles”), a collection of other resources, a
non-virtual object (e.g. a person), and so on. In
other words, any concept that might be the
target of an author’s hypertext reference must
fit within the definition of a resource. A
resource is a conceptual mapping to a set of
entities, not the entity that corresponds to the
mapping at any particular point in time.
http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_2_1_1
5. WTF?
RESTful applications maximize the
use of the pre-existing, well-defined
interface and other built-in
capabilities provided by the chosen
network protocol, and minimize
the addition of new application-
specific features on top of it.
http://en.wikipedia.org/wiki/REST
7. HTTP is RESTful!
• Methods (verbs) GET, PUT, POST, DELETE
• URIs (nouns) map entities to endpoints
• Use response codes for success/error
200 OK (content is in response body)
204 No Content
404 Not Found
500 Internal Server Error
8. and Sinatra!
• Sinatra is a DSL for quickly creating web
applications in Ruby
# myapp.rb
require 'rubygems'
require 'sinatra'
get '/' do
'Hello world!'
end
9. get '/' do
.. show something ..
end
post '/' do
.. create something ..
end
put '/' do
.. replace something ..
end
delete '/' do
.. annihilate something ..
end