So we've learned Ruby, and started thinking about building our own website. Most people, like myself, would want to just jump right in with Rails, HTML, and making everything look pretty with CSS.
But first, we have to understand what's happening when it comes to browsing websites before we can code our own.
So just how does the web work? There are many components to the web, like the internet itself, hardware we use to connect and browse, and they're all connected with HTTP (Hypertext Transfer Protocol).
What is HTTP?
HTTP is a protocol that is used to transfer data over the web. HTTP uses a set of methods that perform various tasks.
To understand what happens when we browse the web, we need to know about the client and server interactions, and the "request-response" cycle.
What is a client?
A client is us! Or more specifically, our computer, phone, or any other hardware that has a browser to access the internet (like Safari, Chrome, or Firefox). We type in a website, and get a response from a server.
What is a server?
A server is a program or device that responds to client requests. It returns information to the browser so we can get the information we requested. Servers can access databases to retrieve and store information as needed.
If we have our browser open, we'll go to www.https://flatironschool.com, we'll be taken to the Flatiron School main page.
Our browser (the client) submits a HTTP request to the server (where Flatiron's website is hosted). The server returns a response, and we get back a HTML page to our browser.
So to simplify;
The client sends an HTTP request on the web.
The server receives the request, and returns an HTTP response to the browser.
Another example would be checking your Facebook feed. When you access Facebook in the browser, you initiate a request to Facebook's server, and they respond with a display of the login page. You go ahead and log in (another request-response, as you're requesting to log in and the server accesses it database and says, "Hey, it's you, you're good!")
Then you're presented with your Facebook feed. All your family and friends selfies, status updates, and location tags are all products of Facebook getting a request to show your feed, then returning a bunch of information stored in its database. All of that information is displayed neatly in your browser.
Every step of loading Facebook.com, logging in, and viewing your feed is an example of the request-response cycle. Note that there can be multiple request and responses happening at the same time! That's how we get a bunch of information so quickly instead of having to wait for each bit to load one by one.
The client side handles all the user interface, and the server stores and retrieves data, processes any logic built into the website, and many other things.
To dive even further concerning the Client-Server, Mozilla's documentation can be found here.
To learn more about HTTP, see their HTTP documentation.
Top comments (0)