by Jon Crosby

A World of Middleware

What if every endpoint (or “origin” in HTTP-speak) was a 404 and everything else was middleware? In Rack-land, this can be a reality. CloudKit, for example, detects if it is the last thing in the stack, inserting a default developer page at the root and a 404 everywhere else. If it is not the last item in the stack, requests for resources that it has not claimed are passed downstream.

If you consider that no web framework or piece of middleware is all-knowing, then this behavior seems to be more flexible than that of the pre-Rack view of the world where the URI space was “everything” by default.

This Gist from Jesse Newland shows a quick hack to make Sinatra behave as middleware for Rack:

There is no reason that Rails and other frameworks should not behave similarly, allowing themselves to be yet another component in a chain leading to the eventual 404 at the end of the stack. I struggle to see the distinction between middleware and “web apps” as anything other than arbitrary.

This concept and a few others provide the idea behind my upcoming talk "In a World of Middleware, Who Needs Monolithic Applications?" at MountainWest RubyConf in March of this year. If you haven’t registered, take a moment to browse the list of speakers and see if there is a way to get away from work for a long weekend.