What is Rack
- uses Ruby's built-in WEBrick web server
- provides a web server interface
- a protocol for building composing web apps
- collection of middleware utilities
Web server interface
Rack provides an interface so that you don't have to deal with some elements of the server. Such as listening on a port, accepting connections, parsing HTTP responses and requests.
This gives you more time to spend on writing what the application does and providing value.
Rack protocol is simply a Ruby object with a call method, being a proc it has a "call" method. The method arguments are the environment variables which describe the incoming request. The return value is an array with [status, headers, body].
- status: The HTTP status code
- headers: hash of HTTP headers for the response
- body: Body of the response.
A simple HelloWorld app in Rack
Entering 'rackup' in the terminal will start our rack up
Accessing the up and running website by going to "localhost:9292"
And That's it!
Within moments we have an app running.