Today I dove deeper into Rack, an application server that's used in software development using Ruby.
I'm still a little fuzzy about some aspects of it, but my understanding is that the main function of Rack is to provide an interface for a web server and Ruby web application to interact.
The implementation details and syntax are still something I'm figuring out.
So far, this is what I understand down👇
👉 Installing Rack
To use Rack, you first need to `gem install` to your project you want to use Rack with.
Then you `require`/import Rack into the web application you want to interface with the web server.
👉 Using Rack
Here's where things get slightly fuzzy for me...
To use Rack with a web application, you first need to define a class that will represent the web application, with an instance method of `call` that takes the `env` as an argument.
The `env` is a data structure produced by Rack that represents and HTTP response passed on from the web server. The `env` is a Hash object that contains key-values that are associated with the different headers of the HTTP response.
The only thing necessary for the `call` instance method is that it must return an Array with these 3 elements:
1. A String representing a status code
2. A Hash that represents the headers and their values
3. An Array (or object that can be iterated over) that represents the body of the HTTP response.
Logic can be applied within the `call` method to "route".
Routing is the concept of using data from an HTTP response to figure out what web application or processes to perform in order to help generate the response.
---
Again, this is still a bit foggy, but I'm working on it.
If there's any critiques or extra tidbits anyone can offer, I would love to hear them! Thank you 😊
• • •
Missing some Tweet in this thread? You can try to
force a refresh