What is Middleware?
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.
- 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::Builderputs 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 servera
Rack::Serverobject is created and attached to the web server (
WEBrickby default), and the middleware components are loaded up. The
Rack::Server#startmethod starts the web server running, listening on the designated port for HTTP requests.
References & Resources
- Dependency injection
- Directives and Pipes
- Data binding
- HTTP Get vs. Post
- Node.js is everywhere
- MongoDB root user
- 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
- Evaluating the Normal Distribution
- What is Nodejs? Advantages and disadvantage?
- How do I debug Nodejs applications?
- Sync directory search using fs.readdirSync