Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: aa847de5ab
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 121 lines (87 sloc) 1.938 kb

!SLIDE

Sinatra

Created by the great Blake Mizerany

@bmizerany

!SLIDE commandline incremental

Install that badboy

$ sudo gem install sinatra

!SLIDE commandline incremental

Set up an app

$ cd /tmp
$ vim app.rb

!SLIDE smaller

How easy is it?

@@@ ruby
require 'rubygems'
require 'sinatra'

get '/' do
    'oh you did NOT just make a little website??!!!?!!'
end

!SLIDE commandline

$ ruby app.rb

!SLIDE smaller code

RESTful

@@@ ruby

get '/' do
    "Hello World!"
end

!SLIDE smaller code

:-(

@@@ ruby

delete '/' do
    "Goodbye World!"
end

!SLIDE smaller code

POST & PUT Too

@@@ ruby

post '/' do
    "Thanks #{params[:name]}"
end

put '/change/something' do
    "Changed or something"
end

!SLIDE smaller commandline incremental

ruby examples/sinazzy.rb

$ curl localhost:4567/
Hello World!
$ curl -X DELETE localhost:4567/
Goodby World!
$ curl -d name=Jesse localhost:4567/name
Hi there Jesse!
$ curl -X PUT localhost:4567/change/something
Changed or something

!SLIDE

It's all about Routes

!SLIDE code

Params

@@@ ruby

get '/hi/:name' do
    "Hello #{params[:name]}"
end

!SLIDE code

Named Params

@@@ ruby

get '/yo/:name' do |n|
    "What's up #{n}"
end

!SLIDE code

We have SPLAT!

@@@ ruby

get '/i/*/*' do
    splat = params[:splat]
    "I #{splat.first} #{splat.last} too!"
end

!SLIDE commandline incremental $ curl localhost:4567/i/love/ruby I love ruby too!

$ curl localhost:4567/i/dislike/puppies
That's a lie!

$ curl localhost:4567/i/dislike/puppies
I dislike puppies too!

!SLIDE smaller

You like regular expressions, right?

@@@ ruby

get %r{/I/am/([\d]+)/years/old} do |age|
    puts age
    # write to stdout. sometimes helpful.
end
Something went wrong with that request. Please try again.