Last active
April 19, 2017 17:56
-
-
Save enoliglesias/741f2be43fda418e3a669bcc3e7b9003 to your computer and use it in GitHub Desktop.
Some examples for my "Rack basics" slides :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Wadus | |
def call(env) | |
['200', {'X-Wadus' => 'Foo'}, ['Rack app with config.ru file']] | |
end | |
end | |
run Wadus.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LoggerMiddleware | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
before = Time.now.to_f | |
status, headers, body = @app.call(env) | |
after = Time.now.to_f | |
puts "[LOGGER] Request time: #{after - before} sec." | |
[status, headers, body] | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack' | |
class Wadus | |
def call(env) | |
['200', {'X-Wadus' => 'Foo'}, ['Class based so simple rack app']] | |
end | |
end | |
Rack::Handler::WEBrick.run Wadus.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack' | |
app = -> (env) do | |
['200', {'X-Wadus' => 'foo'}, ['Proc based so simple rack app']] | |
end | |
Rack::Handler::WEBrick.run app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment