DEV Community

Khafido Ilzam
Khafido Ilzam

Posted on

How does HTTP work?

HTTP is one of the fundamental building blocks of the Internet. It’s the protocol, or language, used to request and receive information from websites and other content sources over the Internet.

What is HTTP?

HTTP stands for Hypertext Transfer Protocol and is a core component of everyday Internet use, acting as a language that enables us to interact with a website to get the information we need. Each time you type a website URL into a browser, click on a link, or click on a mobile web application on your phone, HTTP works behind the scenes to enable information exchange. HTTP is a set of rules for how files – text, images, audio, and video – are transferred over the Internet.

How does HTTP work?

HTTP defines the request-response process that facilitates the information exchange with web-based applications. The client initiates requests, usually using a web browser, and the web server responds with the requested information.

HTTP request-response process

HTTP Request

Every time you type a website address into your browser or click on a mobile web application or link to access some sort of content, you’re launching an HTTP request. An HTTP request is the message a client (web browser) sends to a server asking for a specific action or resource.

A Request HTTP consists of:

  • HTTP method (GET, POST, PUT, or DELETE) indicating the desired action
  • Target URL or resource path, indicating the location of the web resources
  • Version of the HTTP protocol

HTTP Header and Body

Header contains additional information about the request:

  • the browser type
  • accepted content types
  • user-agent information
  • authentication tokens
  • cookies

Body is an optional component that sends additional information that is more likely to be included in a request initiated by an engineer or web developer. For example:

  • a form to submit
  • data to update a profile
  • a file to upload

HTTP Response

An HTTP response is the message the server sends back to the client to reply to the HTTP request. As with HTTP requests, HTTP responses also include several crucial elements in order to work properly.

  1. A status line that includes the HTTP version, status code, and status message.
  2. A response header with additional information about the response, such as content type and length.
  3. A response body that contains the requested data, including text, images, audio, and video.

HTTP Status Code

HTTP status code is something you likely have encountered. Think about that “404 Not Found” message or “301 Moved Permanently.” These are examples of status codes that users receive in response to a request that isn’t successful.

Status codes fall into five main categories: informational, successful, redirection, client errors, and server errors.

Here are some of the most common status codes to be aware of.

200 OK. The request was successful, and the server provided the requested data.

301 Moved Permanently. The URL of the requested resource has been permanently changed.

400 Bad Request. The server cannot understand the client’s request.

401 Unauthorized. The client does now have proper authentication credentials to access a resource on the server.

403 Forbidden. The client’s identity is known, but they do not have permission to access the requested resource.

404 Not Found. The resource could not be found on the server.

500 Internal Server Error. The server cannot fulfill the request because it has encountered a condition it doesn’t know how to handle.

503 Service Unavailable. The server cannot handle the request. Often the situation is temporary and the result of a server being down for maintenance or temporarily overloaded.

Credit: https://www.corero.com/what-is-http-and-how-does-it-work/

Top comments (0)