Today I explored Rack, an awesome API connecting web servers and web frameworks by Christian Neukirchen. Here is an introduction article by Christian Neukirchen.
Rack was insipired from python’s WSGI.
What is Rack?
To put in the words of Christian,
Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.
Instead of going deeper in documentation, I’ll walk through what exactly Rack is, and how it fits in different web-frameworks in Ruby. I’ve put the references at the end of the post, which helped me understand Rack.
Rack is very simple yet very powerful tool. Rack has specifications on how Rack application and web server should communicate. As long as you follow them, you don’t need ‘rack’ gem to develop you framework.
A Rack application is a Ruby object(not a class) that responds to call. It takes exactly one argument, the environment and return an Array of exactly three values: The status, the headers, and the body.
TODO
References:-
- PS: The whole credit of this article goes to the author of References listed above. I have just jotted down, what I learnt today mostly as note for my own reference.