Speaking the Language of the Internet: HTTP 🖥️

Esra Nur Mülkpınar
Bursa Bilişim Topluluğu
11 min readJan 16, 2024

Hello dear developer friends, if the coffees are ready, we are ready too.🚀 Today, our topic is HTTP. I wish you good readings 👩🏻‍💻

HTTP is a communication protocol used on the network worldwide since 1990. It is a protocol that enables the display of web pages you see on the Internet. In this article, we will examine HTTP.

If you haven’t read my Introduction to the Web World article, I recommend taking a look before reading this one.

✨ Topics in this article:

1)HTTP Protocol

  • What is HTTP ?
  • What Does HTTP Do ?
  • How Does HTTP Work ?
  • What Are the Components of HTTP ?
  • HTTP Status Codes

2)HTTPS Protocol

  • What is HTTPS?
  • Differences Between HTTP and HTTPS ?

✨What is HTTP ?

We said that HTTP (Hyper Text Transfer Protocol) is a protocol used for information exchange on the Internet. When you access a website or interact with web services, your browser communicates with servers using HTTP. The HTTP protocol works in a client-server architecture. A request is sent by the client, and a response is received by the server.

The client is the one requesting a service or resource, usually a user or a device; the server is the computer system that fulfills these requests and provides the service.

✨What Does HTTP Do ?

The fundamental tasks of HTTP are as follows:

  1. Data Transmission: HTTP allows users to send data from web browsers to servers and from servers to browsers. This includes the transfer of web pages, images, videos, and other media files.
  2. Request and Response: HTTP is built on a request-response model between the client (browser) and the server. Browsers can request a specific resource (e.g., a web page or an image) from servers, and the server fulfills this request.
  3. Hypertext Transfer: The “Hypertext” part of HTTP enables the transmission of hypertext documents containing text, links, and other media types. This allows web pages and documents to be interconnected, allowing users to navigate between different pages through these links.
  4. Stateless Protocol: HTTP is a stateless protocol. Each request-response pair is independent, meaning it operates independently of previous requests or responses. This implies that each HTTP request is not connected to others, and each request is handled independently.
  5. URL (Uniform Resource Locator) Structure: HTTP provides access to specific resources (e.g., a web page or an image) using URLs. URLs are a standard identification system used to specify the location of a resource.

✨How Does HTTP Work ?

Throughout the day, we access many websites several times. In fact, while performing this process, we unknowingly make requests to different servers. The computer, i.e., the client, sends a request to servers through a web browser.

The receiving server responds to the request through installed server programs. Information about the status of the request is included in the response content, and the requested content can also be included. At this point, the HTTP protocol comes into play and ensures the secure presentation of the request. In other words, HTTP initiates a login request to the server, and when approval is received on the request, the data of the desired site to be accessed appears, thus completing the site entry.

✨What Are the Components of HTTP ?

Every HTTP request made over the Internet carries a series of encoded data types. A typical HTTP request includes the following:

  1. HTTP Version Type (Protokol Version)
  2. URL (Uniform Resource Locator)
  3. HTTP Method
  4. HTTP Request Headers
  5. Optional HTTP Body

HTTP Version Type (Protokol Version):

  • Specifies which version of the HTTP protocol the request is using. For example, “HTTP/1.1” or “HTTP/2.”

URL (Uniform Resource Locator):

HTTP Method :

  • The method specifies the type of operation the client requests from the server. For example, “GET,” “POST,” “PUT,” “DELETE,” etc. Each method represents a specific function, and we will delve into these methods shortly.

HTTP Request Headers :

Headers define the request and its characteristics. Headers can contain additional information about the request or the server. For example:

  • Host: Specifies the name of the server (e.g., “www.example.com").
  • User-Agent: Specifies the type and version of the client (e.g., browser name and version).
  • Content-Type: Specifies the type of content in the request (e.g., “application/json”).

Optional HTTP Body:

  • An optional component that constitutes the body of the request. It is commonly used with methods like “POST” and “PUT” and often carries data. For example, in a “POST” request where a form is submitted, the form data may be included in this section.

Example of an HTTP GET request:

GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0

In this example, the HTTP version is “HTTP/1.1,” the URL is “/index.html,” the method used is “GET,” and the request headers are specified as “Host” and “User-Agent.” There is no body in this request because it is a GET request, which generally does not contain a body.

We’ve examined the components of an HTTP request. Now, let’s take a look at the components of an HTTP response.

✨Components of an HTTP Response

An HTTP response is what web clients (usually browsers) receive from an Internet server in response to an HTTP request.

A typical HTTP response includes:

  1. HTTP Status Code
  2. HTTP Response Headers
  3. Optional HTTP Body

HTTP Status Code :

A three-digit number indicating the outcome of the request. Each status code represents a specific situation. For example:

  • 200 OK: The request was successful.
  • 404 Not Found: The requested resource could not be found.
  • 500 Internal Server Error: An internal server error occurred.

Status codes indicate how the request was processed or whether it was successful. We will explore them in more detail shortly.

HTTP Response Headers (HTTP Yanıt Başlıkları):

Headers that define the characteristics of the response. These headers specify the type, date, content, and other features of the response. For example:

  • Content-Type: Specifies the type of content in the response (e.g., “text/html” or “application/json”).
  • Content-Length: Specifies the length of the response content.
  • Date: Specifies the creation date of the response.

Headers assist browsers and other clients in processing the response and provide additional information.

Optional HTTP Body:

An optional component carrying the content of the response. It contains the data sent by the server in response to the request. For example:

  • An HTML document (text/html)
  • An image file (image/jpeg)
  • A JSON data (application/json)
  • The content type is specified with the “Content-Type” header.

When these components come together, an HTTP response provides users or clients with an information package containing the status, response headers, and optionally, the content of the request. For example:

HTTP/1.1 200 OK
Date: Sat, 15 Jan 2022 12:00:00 GMT
Content-Type: text/html
Content-Length: 1024
<!DOCTYPE html>
<html>
<head>
<title>Example Page</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>

In this example, there is a successful response with a 200 OK status code, headers, and an HTML content.

An important aspect of this communication is the exchange of status codes that provide information about the result of a request. Now let’s take a look at these status codes.

✨HTTP Status Codes

HTTP status codes are three-digit numbers returned by servers to indicate the status of a client’s request made to the server. They are an essential part of the HTTP protocol, providing information about the processing of a request and whether it was successful or encountered an issue.

💡1xx — Informational:

Informational codes indicate that the server has received the request and is continuing the process. The client should wait for further instructions.

  • 100 Continue: The client has sent a request to the server asking for permission to continue.
  • 101 Switching Protocols: The server has accepted a request to switch to a new communication protocol.
  • 102 Processing: The server has received and is processing the request, but has not completed the response. The client should inquire about the status again after a specific period.
  • 103 Early Hints: The server has not yet generated the response body, but is sending early information to the client.

💡2xx — Success:

Success codes indicate that the client’s request was successfully received, understood, and accepted. The most common code in this category is the standard successful HTTP request code, 200 OK.

  • 200 OK: The request has been successfully completed. The server has processed the client’s request successfully and returned a response.
  • 201 Created: The request has created a new resource, and the server has successfully created that resource.
  • 202 Accepted: The server has received the request but has not yet acted upon it. It indicates that there is a resource to be processed.
  • 204 No Content: The server has successfully processed the request, but the response body does not contain any content. The client understands that it should not change the current page.
  • 206 Partial Content: The server sends a partial content response for a request that specified a range of content. This is often used for delivering parts of large files.

💡3xx — Redirect:

Redirect codes indicate that the client needs to take additional action to complete the request. For example, the 302 Found code tells the client to follow a different URL to obtain the requested resource.

  • 300 Multiple Choices: The request has more than one possible response. The user or client must choose one option. This status code indicates situations where there are multiple alternative resources available.
  • 301 Moved Permanently: The requested resource has been permanently moved to a new location. The client should redirect future requests to the new location.
  • 304 Not Modified: The client has requested a resource previously, and the server indicates that the resource has not been modified since that date. The client can use its cached copy.
  • 307 Temporary Redirect: The requested resource has been temporarily moved to a different location. The client should redirect future requests to the new location, while preserving the original HTTP method.
  • 308 Permanent Redirect: The requested resource has been permanently moved to a different location. The client should redirect future requests to the new location, preserving the original HTTP method.

💡4xx — Client Error:

Client Error codes indicate that there is a problem with the client’s request. Common examples include 404 Not Found (requested resource not found) and 401 Unauthorized (authentication is required).

  • 400 Bad Request: The request sent by the client could not be understood or processed by the server. There may be an error in the request format.
  • 401 Unauthorized: The client requested access to a resource that requires authentication, but it either did not provide valid credentials or the authentication failed.
  • 403 Forbidden: The client does not have permission to access the resource. The server indicates that the client is not authorized to access the requested resource.
  • 404 Not Found: The requested resource could not be found on the server. This status code indicates that the resource requested by the client is not available on the server.
  • 409 Conflict: The request sent by the client conflicts with the existing resources on the server. This status code indicates a situation causing conflict, such as in concurrent editing conflicts.

💡5xx — Server Error

Server Error codes indicate that the server could not fulfill a valid request. 500 Internal Server Error is used as a code that indicates a general error.

  • 500 Internal Server Error: An unexpected internal error occurred while the server was processing a request. This status code indicates a problem on the server side, and the request could not be completed successfully.
  • 501 Not Implemented: The server does not have the functionality required to fulfill the request, or it does not understand the request.
  • 502 Bad Gateway: The server attempted to forward a request through another server or gateway, but that gateway or server responded with a faulty response.
  • 503 Service Unavailable: The server is temporarily unavailable or overloaded. This status code indicates that the server is temporarily unable to handle the request.
  • 504 Gateway Timeout: The server attempted to forward a request through another server or gateway, but that gateway or server did not respond within a specified time. This status code indicates that the expected response from a gateway has timed out

✨HTTP Methods and Functions

HTTP methods express specific actions and enable data transmission between web servers and clients, determining how the server should respond.

💡GET:

  • Function: Used to retrieve the resource at the specified URI.
  • Example Usage: Viewing a web page in a web browser.

💡POST:

  • Function: Used to add a new resource to the specified URI or update an existing resource.
  • Example Usage: Filling out and submitting a form.

💡PUT:

  • Function: Used to add a new resource to the specified URI or update an existing resource. However, it typically replaces the entire resource, meaning it completely replaces an existing resource.
  • Example Usage: Uploading a file or completely changing a resource.

💡DELETE:

  • Function: Used to delete a resource at the specified URI.
  • Example Usage: Deleting a resource.

💡PATCH:

  • Function: Used to make a partial update to a resource at the specified URI.
  • Example Usage: Updating a specific field of a resource.

💡HEAD:

  • Function: Similar to the GET method but only retrieves header information without fetching the actual data. Typically used to obtain metadata about a resource.
  • Example Usage: Getting the last modification date of a file.

💡OPTIONS:

  • Function: Used to query the HTTP methods and other properties applied to a resource at the specified URI.
  • Example Usage: Checking the supported methods by a server.

💡TRACE:

  • Function: Used to trace the route of a request to a resource at the specified URI. Often used for debugging purposes.
  • Example Usage: Checking how requests are routed

💡CONNECT:

  • Function: Used to establish a connection to another server through a proxy server and use the proxy server as a tunnel.
  • Example Usage: Accessing a server using a proxy server for secure connections (HTTPS).

✨What is HTTPS?

HTTP (Hypertext Transfer Protocol) and HTTPS (HTTP Secure) are both protocols used for exchanging information over the internet. However, there are significant differences between them. Let’s take a look at these differences now.

Differences Between HTTP and HTTPS:

In today’s web environment, websites often lean towards using HTTPS for security and privacy reasons, especially when users enter personal information or conduct financial transactions. HTTPS encrypts data transmission, ensuring the security of user information and providing a more secure online experience. Let’s explore the differences between HTTP and HTTPS.

Security:

  • HTTP: Data transmission is not encrypted, making transmitted information readable. There is a privacy risk for data transmissions over insecure connections.
  • HTTPS: Data transmission is encrypted, ensuring the secure transmission of user and site information. HTTPS uses SSL/TLS (Secure Sockets Layer/Transport Layer Security) protocols for encryption.

URL Structure:

  • HTTP: URL starts with “http://."
  • HTTPS: URL starts with “https://." This represents a secure connection.

Port Number:

  • HTTP: Typically uses port 80.
  • HTTPS: Typically uses port 443.

Security Certificate:

  • HTTP: Does not require a security certificate.
  • HTTPS: Requires an SSL/TLS certificate to establish a secure connection. This certificate authenticates the visited website.

SEO Impact:

  • HTTP: Not secure. Google and other search engines may give preference to sites using HTTPS, highlighting secure sites.
  • HTTPS: Uses a secure connection and may provide SEO advantages.

Cookie Security:

  • HTTP: Cookies are transmitted unencrypted, posing a security risk.
  • HTTPS: Cookies are encrypted, ensuring a more secure transmission.

If you enjoyed the text, don’t forget to check out my other content. Happy reading! 📚

You can buy me a coffee to support me 🌟

If you want to get in touch with me: Esra Nur Mülkpınar

--

--