Movatterモバイル変換


[0]ホーム

URL:


Skip to Content
Articles

What is HTTP? Understanding HTTP Requests

What is HTTP?

HTTP (Hypertext Transfer Protocol) is used to structure requests and responses over the internet. HTTP requires data to be transferred from one point to another over the network. The transfer of resources happens using TCP (Transmission Control Protocol). In viewing this webpage, TCP manages the channels between your browser and the server (in this case,codecademy.com).

TCP is used to manage many types of internet connections in which one computer or device wants to send something to another. HTTP is the command language that the devices on both sides of the connection must follow in order to communicate.

Next, let’s learn what anHTTP request is and how it works.

What is an HTTP request?

An HTTP request is a structured message that a client (such as a browser, mobile app, orAPI tool) sends to a server to request a resource or trigger an action. These resources can be anything from HTML pages and images to files, videos, or even database records.

Every HTTP request follows a standard format, which generally includes:

1.Request line: Specifies the HTTP method (e.g.,GET,POST), the resource path (e.g.,/index.html), and the protocol version (e.g.,HTTP/1.1).

  • Example:GET /index.html HTTP/1.1

2.Headers: Provide additional context or metadata about the request. Common headers include:

  • Host: Indicates the domain name of the server.
  • User-Agent: Identifies the client (e.g., Chrome, Firefox).
  • Accept: Informs the server what type of content the client can handle (e.g.,HTML,JSON).
  • Authorization: Sends authentication credentials when accessing protected resources.

3.Body (Optional): Includes data sent to the server, typically inPOST,PUT, orPATCH requests. For example, when submitting a login form, the username and password are sent in the body.

Upon receiving the HTTP request, the server processes it according to the provided instructions. If successful, it responds with an HTTP response that contains:

  • A status code (e.g.,200 OK,404 Not Found,500 Internal Server Error)
  • Response headers with metadata
  • An optional response body (such as a webpage, JSON data, or an image)

In short, an HTTP request acts like a conversation starter between a client and server: the client asks for something, and the server replies with either the requested resource or an explanation of why it cannot be provided.

Now, let’s explore the different types of HTTP requests.

Types of HTTP requests

HTTP supports several request methods, each serving a unique purpose. The most common ones include:

  • GET: Retrieves data from the server (e.g., loading a webpage).
  • POST: Sends data to the server.
  • PUT: Updates existing data on the server.
  • DELETE: Removes specified data from the server.
  • HEAD: Retrieves only headers of a resource, without the actual content.
  • PATCH: Applies partial modifications to a resource.
  • OPTIONS: Describes communication options available for a resource.

Now, let’s see how these HTTP request methods work in practice.

How HTTP requests work

When you type an address such aswww.codecademy.com into your browser, you are commanding it to open a TCP channel to the server that responds to that URL. A URL is like your home address or phone number because it describes how to reach you.

In this situation, our computer, which is making the request, is called the client. The URL you are requesting is the address which belongs to the server.

Once the TCP connection gets established, the client sends an HTTPGET request to the server to retrieve the webpage it should display. After the server has sent the response, it closes the TCP connection. If you open the website in your browser again or if your browser automatically requests something from the server, a new connection is opened, which follows the same process described earlier.

Example: Sending an HTTPGET request

Let’s explore an example of howGET requests (the most common type of request) are used to help your computer (the client) access resources on the web.

Suppose we want to check out the latest course offerings fromhttp://codecademy.com. After we type the URL into our browser, our browser will extract thehttp part and recognize that it is the name of the network protocol to use. Then, it takes the domain name from the URL (in this case,codecademy.com) and asks the DNS (Domain Name Server) to return an IP (Internet Protocol) address.

Now, the client knows the destination’s IP address. It then opens a connection to the server at that address, using thehttp protocol as specified. It will initiate aGET request to the server, which contains the IP address of the host and optionally a data payload. TheGET request contains the following text:

GET / HTTP/1.1 Host: www.codecademy.com

This identifies the type of request (GET), the path onwww.codecademy.com (/) and the protocol (HTTP/1.1).HTTP/1.1 is a revision of the first HTTP, which is now calledHTTP/1.0. InHTTP/1.0, every resource request requires a separate connection to the server.HTTP/1.1 uses one connection more than once, so that additional content (like images or stylesheets) is retrieved even after the page has been retrieved. As a result, requests usingHTTP/1.1 have less delay than those usingHTTP/1.0.

The second line of the request contains the address of the server (www.codecademy.com). There may be additional lines as well depending on what data your browser chooses to send.

If the server is able to locate the path requested, the server might respond with the header:

HTTP/1.1 200 OK Content-Type: text/html

This header is followed by the content requested, which in this case is the information needed to renderwww.codecademy.com.

The first line of the header,HTTP/1.1 200 OK, is confirmation that the server understands the protocol that the client wants to communicate withHTTP/1.1 and an HTTP status code signifying that the resource was found on the server. The second line,Content-Type: text/html, shows the type of content that it will be sending to the client.

If the server is not able to locate the path requested by the client, it will respond with the header:

HTTP/1.1 404 NOT FOUND

In this case, the server identifies that it understands the HTTP protocol, but the404 NOT FOUND status code signifies that the specific piece of content requested was not found. This might happen if the content was moved or if you typed in the URL path incorrectly or if the page was removed.

We’re now aware of what HTTP requests are and how they work, but what about HTTPS requests?

What is an HTTPS request?

An HTTPS (Hypertext Transfer Protocol Secure) request is essentially the secure version of an HTTP request. It uses the same structure (request line, headers, and optional body), but all the client-server communication is encrypted using SSL/TLS (Secure Sockets Layer / Transport Layer Security). This ensures that the information exchanged cannot be easily intercepted, altered, or stolen.

When you visit a website that starts withhttps://, your browser and the server perform a process called the TLS Handshake before any data is exchanged. During this handshake:

  1. The browser sends a secure connection request to the server.
  2. The server responds with its digital certificate (issued by a trusted CA or Certificate Authority).
  3. The browser verifies the certificate’s authenticity.
  4. If trusted, both sides agree on an encryption method and generate secure keys for communication.

From this point onward, all HTTP requests and responses are encrypted. For example, if you send login details through an HTTPS request, your username and password are scrambled using encryption algorithms, making them unreadable to attackers who might intercept the traffic.

Lastly, let’s check out the differences between HTTP requests and HTTPS requests.

HTTP requests vs HTTPS requests

Here are the differences between HTTP requests and HTTPS requests:

FeatureHTTP requestsHTTPS requests
SecurityNo encryption; data is sent in plain textEncrypted using SSL/TLS to secure data
Data safetyVulnerable to interception, eavesdropping, and tamperingProtects data confidentiality and integrity
AuthenticationNo verification of server identityUses digital certificates to verify server
Browser indicatorOften marked asNot Secure in browsersShows a padlock icon to indicate security
Use casesSuitable for non-sensitive data (e.g., static content)Essential for sensitive data (e.g., payments, login forms)
PerformanceSlightly faster (no encryption overhead)Slightly slower, but modern optimizations make it comparable

In short, HTTP requests are suitable only for basic, non-sensitive communication, while HTTPS requests are the secure, trusted standard for modern web interactions.

Conclusion

In this guide, we discussed HTTP requests in detail, covering what they are, their different types, and how they work. Besides that, we also touched on HTTPS requests and compared them with HTTP requests to understand how they differ in their functionalities.

HTTP requests are the backbone of communication on the web, enabling browsers and servers to exchange data. With different request methods, clients can retrieve, send, update, or delete resources. While HTTP provides the basic functionality, HTTPS adds essential security, ensuring safe communication and protecting user data.

If you want to learn more about HTTP requests, check out theLearn #"domain-agnostic-link" href="https://www.codecademy.com/article/what-is-javascript">JavaScript, images, videos, etc.) between clients (like browsers) and servers

  • Enabling communication for REST APIs and many web services
  • Building the foundation of the World Wide Web
  • 4. What is the difference between HTTP and TCP?

    • HTTP is an application-layer protocol that defines how messages are formatted and transferred over the web.
    • TCP is a transport-layer protocol that ensures reliable data delivery between devices.

    5. What is the difference between HTTP request and API request?

    • An HTTP request is a general request for web resources like pages, images, or scripts, usually made by browsers and returning content for users.
    • An API request is a specific type of HTTP request that targets an API endpoint, typically returning structured data like JSON or XML for use by applications or services.
    Codecademy Team

    'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'

    Meet the full team

    Related articles

    Learn more on Codecademy

  • Use test-driven development to create a JavaScript server using the Express framework.
    • Intermediate.
      1 hour
  • Contents

    [8]ページ先頭

    ©2009-2025 Movatter.jp