You opened my website to read this article right? Through a button or a link some where right? And all of a sudden, your browser got my website into your device from the internet fast away. Magical, isn't it? ☺️
But how did it do that? Let's get into it.
Clients and Servers
Out there on the wild internet, there are two main components, one requesting for data and the other providing the data.
The client is the component that is requesting for the data and the server is the other component that has the data in store and provides it to the client upon request.
A client could be any form of application that is requesting for data. In your case a browser.
Clients communicate with a server using HTTP requests, HyperText Transfer Protocol requests.
HTTP Requests
An HTTP request has four main parts, they are
- The URL ⇒ this is what identifies the server.
- The method ⇒this is the kind of request the client is trying to make.
- Other encoded data in the request body.
- Cookies ⇒ some websites and apps use this to check for authentication and other things.
Let's take a closer look at The request methods.
There are five main types of request message with other ones also available. They are; GET
, HEAD
, POST
, PUT
, and DELETE
.
GET
A GET
request is used to request for specific resources from a server. For example an HTML page containing the names of employees in a company or a list of the names of the employees.
HEAD
A HEAD
request is used to ask the server about information ( metadata ) on a specific resource rather than requesting for the resource like GET
will do. For example, the last time the resource was updated.
POST
A POST
request is used to send data to the server. This data is usually and encoded in the body of the request.
PUT
This method is used to update existing data on the server. If the data does not exist it is created.
DELETE
The name of this request says it all. It is used to delete existing data on the server. Carefully used😏.
After a client has requested for data from a server, the server takes in the request processes it and responds with an HTTP response code. These codes tell whether the request was successful or not. If the request is successful the response also has a body that would contain the requested resource.
HTTP Response Codes
There are numerous HTTP response codes a server could return and they all have their meanings. Let's look at the popular ones.
- 200 OK ⇒ This means, the request was successful.
- 404 Not Found ⇒ This means the requested resource could not be found on the server.
- 403 Forbidden ⇒This means the user requesting for the resource is not authorized to view it.
If the request was a successful one, the data or resource requested for would be in the body of the response.
If it's an HTML page, the browser renders it and makes additional requests for CSS and JavaScript in the page.
Now we understand how our internet works with HTTP requests. Don't hesitate to reach out to me for any reason... I'm always available and I love sharing what I know.
😇 I'm Aikins and I love building software to help people.
See you IRL.