Browse files

middleware content

  • Loading branch information...
1 parent 1bacda0 commit 6a1066d56ff9b8e23b707273a999ba95d8905381 @stevenwilkin committed Mar 27, 2012
Showing with 55 additions and 1 deletion.
  1. +18 −0 05_middleware/01_rack.md
  2. +36 −0 05_middleware/02_runtime_example.md
  3. +1 −1 showoff.json
View
18 05_middleware/01_rack.md
@@ -1,3 +1,21 @@
!SLIDE
+# Rack middleware
+
+
+!SLIDE
+
+# Rack
+
+_Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks_
+
+[http://rack.rubyforge.org/](http://rack.rubyforge.org/)
+
+
+!SLIDE
+
# Middleware
+
+* sits between the web server and your application
+* logging, exception handling, url mapping, http authentication and static file serving can all be dropped in for free
+* I personally use it for API key checking and rate-limiting
View
36 05_middleware/02_runtime_example.md
@@ -0,0 +1,36 @@
+!SLIDE smaller
+
+# Runtime example
+
+ @@@ ruby
+ # 05_middleware.rb
+ require 'sinatra'
+
+ class Runtime
+ def initialize(app)
+ @app = app
+ end
+ def call(env)
+ start_time = Time.now
+ status, headers, body = @app.call(env)
+ headers['X-Runtime'] = "%0.6f" % (Time.now - start_time)
+ [status, headers, body]
+ end
+ end
+
+ use Runtime
+
+ get '/' do
+ "Hello World!"
+ end
+
+
+!SLIDE small
+
+# Watch the headers
+
+ $ ruby ./05_middleware.rb
+ >> Listening on 0.0.0.0:4567
+
+ $ curl -i -s http://0.0.0.0:4567 | grep Runtime
+ X-Runtime: 0.000268
View
2 showoff.json
@@ -9,7 +9,7 @@
},{
"section": "04_testing"
},{
- "section": "05_middlware"
+ "section": "05_middleware"
},{
"section": "06_real_world"
},{

0 comments on commit 6a1066d

Please sign in to comment.