What is Middleware?
Introduction
If you look at Application Architecture, middleware is in fact the middle of the architecture. It really is the meat of a web application. From following figure, you see the MVC design pattern is implemented as a part of middleware. Actually, it is implemented on top of the middleware.
Definition of Middleware
Middleware is the "software glue" betwen the operating system and applications on each side of a client-server architecture, some refer to it as the "dash" in client-server.
Middleware could be considered as the software that provides services to applications beyond those available from the underlying operating system - it connects applications running on the server side, and pass data between them.
Middleware allows multiple processes running on different machines to interact.
Rails Middleware
- In Rails, a middleware called Rack, is automatically provided.
- Rack provides a unified and simple interface that allows applications to "talk to" web server, including Mongrel, Thin, Phusion, Apache, etc
For example: Rack is responsible for handling HTTP requests and responses. - Rack is used to group and organize modules, typically written in Ruby, and to specify the dependencies between them.
Rack::Builder
puts these together, creating a stack-like structure that can be used by a web application. To see the middleware installed in a Rails application, from the root of the application, type:$ rake middleware
- Other Ruby frameworks, e.g., Sinatra, are also built on top of Rack, but it doesn't have the database backend.
- For the default middleware configuration that Rails provides – it’s useful to know what’s “under the hood.”
- When you execute:
$ rails server
aRack::Server
object is created and attached to the web server (WEBrick
by default), and the middleware components are loaded up. TheRack::Server#start
method starts the web server running, listening on the designated port for HTTP requests.
References & Resources
- N/A
Latest Post
- Dependency injection
- Directives and Pipes
- Data binding
- HTTP Get vs. Post
- Node.js is everywhere
- MongoDB root user
- Combine JavaScript and CSS
- Inline Small JavaScript and CSS
- Minify JavaScript and CSS
- Defer Parsing of JavaScript
- Prefer Async Script Loading
- Components, Bootstrap and DOM
- What is HEAD in git?
- Show the changes in Git.
- What is AngularJS 2?
- Confidence Interval for a Population Mean
- Accuracy vs. Precision
- Sampling Distribution
- Working with the Normal Distribution
- Standardized score - Z score
- Percentile
- Evaluating the Normal Distribution
- What is Nodejs? Advantages and disadvantage?
- How do I debug Nodejs applications?
- Sync directory search using fs.readdirSync