Rack and Middlewares
Goal of this lesson is to understand what middlewares in Rack are good for.
Start with these articles:
You should be able to answer the following questions:
- What is Rack?
- How does Rack relate to Ruby on Rails?
- What is Rack middleware?
- What are some advantages of implementing functionality as a middleware as opposed to e.g. a
Now look at the middleware stack of a freshly installed Rails application. For each middleware in the stack:
- What does it do?
- What would happen if we removed it from the stack?
- Can you find the code that implements it?
We are using the
exception_notification gem to receive an e-mail whenever one of our apps raises an unhandled exception.
Look through the repo and understand how it does this (hint: it’s a middleware!).
- Write a Middleware that makes a Rails application respond to
GET /hellowhen added to the middleware stack. The path would simply print
HI WORLDwith a
- Write a Middleware that prints
OUCHto the screen whenever the Rails application raises an unhandled error.