Posted over 3 years ago. Visible to the public. Deprecated.

Rack and Middlewares

Streamlining the curriculum.

Goal of this lesson is to understand what middlewares in Rack are good for.

Rack

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 before_filter in ApplicationController?

Rails middleware

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?

Exception Notification

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!).

Excercises

  • Write a Middleware that makes a Rails application respond to GET /hello when added to the middleware stack. The path would simply print HI WORLD with a text/plain content type.
  • Write a Middleware that prints OUCH to the screen whenever the Rails application raises an unhandled error.

Owner of this card:

Avatar
Henning Koch
Last edit:
27 days ago
by Henning Koch
Posted by Henning Koch to makandra Curriculum
This website uses cookies to improve usability and analyze traffic.
Accept or learn more