I can program and develop in Ruby on Rails/JS/HTML/CSS to make a full stack app. However, there are holes in my understanding of the HTTP request/response cycle. Are the following points correct?
- If I make a Rails app, and on the command line type
rails serverI get a local server, which I can make requests to. If I open a browser, typelocalhost:3000, and press enter, I am making an HTTP request to the local server. - Rails uses by default a web server called WEBrick, though there are others like Thin, Puma, and Unicorn. These are all pieces of software, and what makes them web servers is the fact that the software implements functionality to process HTTP requests.
- When I run a local web server, it means that my computer is running one of these pieces of software that listen for HTTP requests.
Is the above what it means "to run a local web server"?
- I have seen other examples of ways to "run a local web server". One of the is to run
npm install -g http-serverin a project directory, and then navigate tolocalhost:8080. Is this also just software that starts running and accepts HTTP requests on port 8080? - On a Ruby command line, install rack gem:
gem install rack. Then in a new Ruby file werequire 'rack', start a web server:
Rack::Server.start({ app: MySimpleApp, port: 3000 })
We can then define a web application MySimpleApp that is rack-compliant (object that responds to call method):
class MySimpleApp
def self.call
(...)
end
end
So now when we navigate in our browser to localhost:3000, MySimpleApp is executed. Is rack simply running it's default WEBrick server? Is what the above commands do simply run a local web server and define what to do when an HTTP request comes in (execute MySimpleApp)?