34
@happynoff http://www.tinci.fr What is Rack? Ruby don't hurt me, no more

What is Rack ?

Embed Size (px)

Citation preview

@happynoff http://www.tinci.fr

What is Rack?Ruby don't hurt me, no more

@happynoff http://www.tinci.fr

bit.ly/what-rack

@happynoff http://www.tinci.fr

A Ruby Webserver Interface

@happynoff http://www.tinci.fr

Web Server Your Ruby Application

)!(@*#&$^%MiNsWaNWhOOPsWHaTeVer

@happynoff http://www.tinci.fr

Web Server Your Ruby ApplicationRack

Yup!Here you go!

Huh, I've this request… Do you

know what it's about?!

@happynoff http://www.tinci.fr

Web Server Your Ruby Application

Huh, I've this request… Do you

know what it's about?!

Rack

Well, let me check…

@happynoff http://www.tinci.fr

Web Server Rack

Hey girl, there's this guy asking about a request and all…

Your Ruby Application

Of course! Here's for you.

Have fun!

@happynoff http://www.tinci.fr

Web Server Your Ruby Application

Thanks, you're very kind.

Rack

Ok! Here is what I've made for

you.

@happynoff http://www.tinci.fr

Responses!

@happynoff http://www.tinci.fr

[ , , ]Status Headers Body

@happynoff http://www.tinci.fr

[ "200", { "Content-Type" => "text/html" }, ["Hello world!"] ]

@happynoff http://www.tinci.fr

Web Server Your Ruby ApplicationRack

HTTP GET /…

@happynoff http://www.tinci.fr

Web Server Your Ruby ApplicationRack

HTTP GET /…

@happynoff http://www.tinci.fr

Web Server Your Ruby ApplicationRack

env

@happynoff http://www.tinci.fr

Web Server Your Ruby ApplicationRack

env

@happynoff http://www.tinci.fr

Rack

Middleware

Middleware

Middleware

Middleware

Middleware

server

app

@happynoff http://www.tinci.fr

Rack

Middleware

Middleware

Middleware

Middleware

Middleware

app

server

@happynoff http://www.tinci.fr

Middle-what?

@happynoff http://www.tinci.fr

class MyMiddleware

end

@happynoff http://www.tinci.fr

class MyMiddleware def initialize(app) @app = app end

end

@happynoff http://www.tinci.fr

class MyMiddleware def initialize(app) @app = app end

def call(env) @app.call(env) end end

@happynoff http://www.tinci.fr

class Trollware def initialize(app) @app = app end

def call(env) status, headers, resp = @app.call(env) ["404", headers, resp.body] end end

@happynoff http://www.tinci.fr

And Rails?

@happynoff http://www.tinci.fr

$ rake middleware

@happynoff http://www.tinci.fr

use Rack::Sendfile use ActionDispatch::Static use Rack::Lock use #<ActiveSupport::Cache::Strategy::…> use Rack::Runtime use Rack::MethodOverride use ActionDispatch::RequestId use Rails::Rack::Logger use ActionDispatch::ShowExceptions use WebConsole::Middleware use ActionDispatch::DebugExceptions use ActionDispatch::RemoteIp use ActionDispatch::Reloader use ActionDispatch::Callbacks use ActiveRecord::Migration::CheckPending use ActiveRecord::ConnectionAdapters::… use ActiveRecord::QueryCache use ActionDispatch::Cookies use ActionDispatch::Session::CookieStore use ActionDispatch::Flash use ActionDispatch::ParamsParser use Rack::Head use Rack::ConditionalGet use Rack::ETag run MyApp::Application.routes

@happynoff http://www.tinci.fr

ActionDispatch::Static

@happynoff http://www.tinci.fr

ActionDispatch::ParamsParser

@happynoff http://www.tinci.fr

run MyApp::Application.routes

@happynoff http://www.tinci.fr

Resources

@happynoff http://www.tinci.fr

guides.rubyonrails.org/

rails_on_rack.html

@happynoff http://www.tinci.fr

https://github.com/rack/

rack-contrib

@happynoff

inciwww.tinci.fr

Simon Courtois, Software Architect at

Ruby on Rails, .NET, EmberJS

@happynoff http://www.tinci.fr

Questions?

@happynoff http://www.tinci.fr

Thanks