11
Sinatra By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

Embed Size (px)

Citation preview

Page 1: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

SinatraBy: Maksim

Surguy & Cesar Acosta

require 'sinatra‘get ‘/' do "Hello World!" end

Page 2: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

What is it ?Web application framework in RubyDSL* for defining RESTful HTTP actionsFastFun!

What it is not ?Not RailsNot MVC

*Domain specific Language

Page 3: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

How does it work ? gem install sinatra

vi my_app.rb

set :port, 3000require ‘sinatra’get ‘/’ do

‘Hello World’end

ruby my_app.rb

Page 4: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

Gem ShotgunGems More CondensedChanges to the App require to restart the server

gem install shotgunRun => shotgun my_app.rb

Page 5: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

Got Parameters ? vi my_app2.rb

require ‘sinatra’set :port, 3000

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

ruby my_app2.rb

Page 6: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

Got REST ? get '/' do .. show something .. end

post '/' do .. create something .. end

put '/' do .. update something .. end

delete '/' do .. annihilate something .. end options '/' do .. appease something .. end

Page 7: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

Got views?Supports practically every template engine in Ruby:

HAMLERBErubisBuilderNokogiriSassLessLiquid

And many, many more !!! (http://www.sinatrarb.com/intro.html)

require ‘haml‘get ‘/' do haml :indexend Renders ./views/index.haml

Page 8: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

What is good for ?APIsWeb services (fast !!!)Quick minimal applicationsLean web development (Largely static sites with some dynamic content)Deploy on Heroku!

Page 9: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

In the wild… (Used by)HerokuGitHub servicesEngine YardApartment TherapyMany Others

More examples at : http://www.sinatrarb.com/wild.html

Page 10: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

Resourceshttp://www.sinatrarb.comhttp://sinatra-book.gittr.com/http://bcc2010-sinatra.heroku.com/http://empty-journey-91.heroku.com/ http://net.tutsplus.com/tutorials/ruby/singin

g-with-sinatra/ http://www.slideshare.net/oisin/simple-web-

services-with-sinatra-and-heroku-6882369 http://sinatra-book-contrib.com

Page 11: By: Maksim Surguy & Cesar Acosta require 'sinatra‘ get ‘/' do "Hello World!" end

Thanks!