What is HTTP and HTTPS?
Tags: webdev, internet, beginners
Published: 2022-12-29 09:07:32

HTTP(i.e. Hypertext Transfer Protocol) is a client-server protocol which allows fetching of resources, such as HTML documents.

What does this mean?
**
I know this might look confusing at first, but it is not that complicated. To understand the above definition, it is important to know about client-server communication. So let’s see what does the client-server communication mean.**


**Client-Server Communication**
Have you ever wondered what happens when you search something in the browser or how the webpage is displayed in the browser?

Webpages are basically files or documents that the browser requests from the server. A server is a computer which is located somewhere in the world. So when you search for a webpage (for example “www.google.com”), the client(i.e. the browser) requests some documents from the server and the server responds with the documents that displays the webpage on your browser.

_Ok, but what’s the role of HTTP in this client-server communication?_

Well, to have a client-server communication, there is need of some language or way of communication and HTTP does the job for both the client and the server. HTTP is a protocol, i.e. a set of rules through which the client and server can send and receive messages from each other. The messages sent by the client(i.e. the browser) are called requests and those sent by the server are known as response messages.


![Client-Server Communication](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aciy8c75pp9gh1jbtyir.png)

Proxies: There are numerous computers between the client and the server that work on application layer called as proxies. These proxies help to transfer the http requests, with or without any modification between the client and the server. The proxies that forward the requests without altering or modifying the requests are transparent proxies and those that change or modify the requests are non-transparent proxies.

Now as you have a basic understanding of how client and server communicate, let’s see what are the various HTTP request methods and the response messages.

**HTTP Methods**
![Http Methods](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3hh726rb8cbkvtm6e1ag.png)

HTTP methods are the used by the client to send request messages to the server. The four main HTTP methods that are commonly used are:

GET
POST
PUT
DELETE
Let’s see what does each of these methods mean through examples:

**GET method **: The GET method is used(by the client) to request and read data from the server. So, when you type www.google.com or any web address, the client uses the GET method to request documents from the server and then read those documents to display the webpage.

**POST method**: The POST method is used to send data to the server to create a resource. If you are creating an account(i.e. registering a user) on an online platform, it is a POST request that creates a new user.

**PUT method**: Suppose you are trying to change or update your account profile image, that’s a PUT request. The PUT method is used to update the existing resources.

**DELETE method**: This method is used to request the server for removing a resource. So, to delete a user account, DELETE method is used.


![HTTPs Method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9zzgzwy768fmyvlj131.png)

**HTTP Response Messages**
Okay, so the client sends requests to the server for reading, creating or modifying the resources as we have discussed before, but how will the client know if the requested thing is done or there is some problem regarding the request?

Have you seen something like _“404 Not Found”_ after opening a webpage on your browser? What does that message mean?

Well, this message is nothing else, but the response from the server to the client’s request. 404 is the response status code sent by the server which means the resource that the client has requested is not found. There are various status codes or messages that the server sends to the client for different purposes.

Here are some of the common HTTP response messages:

**200 (OK)** : This status code mean that the request from the client is successful.

**304 (Not modified)** : This status code means that the response is not modified (commonly sent to the browser when we refresh a webpage).

**400 (Bad Request)** : This status code is sent by the server when it doesn’t understand the request.

**404 (Not found)** : As we have discussed before, this status code is sent by the server when the requested resource is not found.

**500 (Internal server error)** : This means there is an error in the server.

There are many status codes like this and if you are curious to know more about various status codes then here is a great [resource](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) for you!

So, **HTTP(i.e. Hypertext Transfer Protocol) is a client-server protocol which allows fetching of resources, such as HTML documents.** Yeah, the thing we discussed before makes more sense now!

**HTTP is stateless**
Stateless protocol means that the server does not keep track of any state information and every request from the client is treated as individual request. Each request does not have a reference to any other request made by the client (i.e. the browser). This means the server does not keep any knowledge about the request after executing it and sending back the response to the client.

For example, if the client makes a GET request to the server, the client-server communication takes place, i.e. server responds back to the client and after that, the server is disconnected from the client. This means that the server now forgets about the GET request made from the client without keeping any history or state. So, every time the client makes a GET request, it is treated as a new request.

**HTTPS**
HTTPS (Hypertext Transfer Protocol Secure) is the secure (or encrypted) version of HTTP protocol. It uses **TLS** or **SSL** encryption to make sure that nobody other than the client and the server can read the response and the request messages. So whenever you enter any information (like email and passwords) on a website, always make sure that the website is using **HTTPS**(by checking its web address that should start with https://).

_In summary_

The above describes a good summary of how the http protocol works,
set an address, establish a connection and then let communication and data transfer occur between a client and server using requests and responses cycles.

It’s important to note that a server can serve several clients, but that introduces concepts of load balancing on the server side that is definitely out of scope for this topic.