What Is HTTP
Table of Contents
Introduction #
HTTP (Hypertext Transfer Protocol) is a protocol for transferring information, such as HTML files. It’s the foundation of data communication for the World Wide Web. In a typical HTTP session, the client (such as a browser) sends a request to the server, which sends back a response.
HTTP Request #
A typical HTTP request consists of:
- request line (request method, path, protocol version)
- request header
- empty line
- optional message body
Here is an example of HTTP request message (curl --verbose https://cyrusyip.org/en/
):
|
|
HTTP Request Methods #
HTTP request methods (also called HTTP verbs) indicate the purpose of the request and what to expect. Here are the common request methods:
GET
: request the specified resourcePOST
: sends information to the server
HTTP Response #
A typical HTTP response consists of:
- status line (protocol version, status code, optional explanation of status code)
- response header
- empty line
- optional message body
Here is an example of HTTP response message (curl --verbose https://example.com/
):
|
|
HTTP Status Codes #
HTTP status codes are three-digit numbers that indicate whether an HTTP request has been successfully completed. They are grouped in five classes:
- 1xx (Informational): The request was received, continuing process.
- 2xx (Successful): The request was successfully received, understood, and accepted.
- 3xx (Redirection): Further action needs to be taken in order to complete the request.
- 4xx (Client Error): The request contains bad syntax or cannot be fulfilled.
- 5xx (Server Error): The server failed to fulfill an apparently valid request.
Here are some commonly used HTTP status codes:
103 Early Hints
: This status code lets the user agent preload resources while the server prepares a response.200 OK
: The request succeeded.301 Moved Permanently
: The URL of the requested resource has been permanently changed.302 Found
: The URL of the requested resource has been temporarily changed.403 Forbidden
: The client does not have access permission to the resource.404 Not Found
: The server cannot find the requested resource.500 Internal Server Error
: The server has encountered an unexpected condition that prevented it from fulfilling the request.503 Service Unavailable
: The server is not ready to handle the request. It may be down for maintenance, or it may be overloaded.
References #
- An overview of HTTP - HTTP | MDN
- What is HTTP? | Cloudflare
- HTTP request methods - HTTP | MDN
- RFC 9110 - HTTP Semantics
- HTTP - Wikipedia
Comments powered by giscus. If comments are not loaded, giscus may be blocked by your Internet service provider.
Comments powered by Disqus. If comments are not loaded, Disqus may be blocked by your Internet service provider.