=================================================================================
HTTP (Hypertext Transfer Protocol) is the foundation of data communication for the World Wide Web, where hypertext documents include hyperlinks to other resources that the user can easily access, for example by a mouse click or by tapping the screen. In HTTP messages for API requests, the most commonly found data format is JSON (JavaScript Object Notation).
URL (Uniform Resource Locator) is a reference or address used to access resources on the internet, specifying the location of a file or a page. For example, the URL of a website provides a means to locate and retrieve its webpages on the internet.
An HTTP request message is used in web communication to request data from a server: - Request Start Line: /Get/index.html HTTP/1.0
- Method: GET - This is the HTTP method used to retrieve data.
- Request-URI: index.html - This is the specific file or resource being requested.
- HTTP Version: HTTP/1.0 - This specifies the version of the HTTP protocol being used.
- Request Header: The headers provide additional information about the request.
- User-Agent: Python-requests/2.21.0 - This indicates that the request was made using the Python requests library, version 2.21.0.
- Accept-Encoding: gzip, deflate - This tells the server that the client can accept compressed responses in either gzip or deflate format.
The request start line and headers are essential components of an HTTP request, enabling the client to specify what action to take, what resource to fetch, and how to handle the response. This structure allows for flexible, robust, and efficient web communication.
HTTP status codes are standardized codes in HTTP responses that indicate the result of a server's attempt to process a request. They are grouped into five classes, each defined by the first digit, which represents a specific type of response:
- 1xx - Informational: These status codes indicate a provisional response, primarily to acknowledge that the request was received and is being processed.
- 100 (Continue): The server has received the request headers, and the client should proceed to send the request body.
- 101 (Switching Protocols): The requester has asked the server to switch protocols, and the server has agreed.
- 2xx - Success: These codes indicate that the client’s request was successfully received, understood, and accepted.
- 200 (OK): Standard response for successful HTTP requests.
- 201 (Created): The request has been fulfilled and resulted in a new resource being created.
- 204 (No Content): The server successfully processed the request, but is not returning any content.
- 3xx - Redirection: These indicate that further action needs to be taken by the user agent in order to fulfill the request.
- 301 (Moved Permanently): The requested resource has been permanently moved to a new location.
- 302 (Found): The resource is temporarily located under a different URI.
- 304 (Not Modified): Indicates that the resource has not been modified since the last request.
- 4xx - Client Error: These indicate an error that the client made, such as a bad request or a request for a non-existent resource.
- 400 (Bad Request): The server could not understand the request due to invalid syntax.
- 401 (Unauthorized): The request lacks valid authentication credentials for the target resource.
- 404 (Not Found): The requested resource could not be found on the server.
- 5xx - Server Error: These indicate that the server failed to fulfill a valid request.
- 500 (Internal Server Error): The server encountered an unexpected condition that prevented it from fulfilling the request.
- 502 (Bad Gateway): The server, while acting as a gateway or proxy, received an invalid response from an upstream server.
- 503 (Service Unavailable): The server is currently unable to handle the request due to a temporary overload or scheduled maintenance.
These status codes are a crucial part of the HTTP specification as they provide quick, contextual feedback about the success or failure of HTTP requests.
HTTP methods, also known as request methods, are a set of verbs used in HTTP to indicate the desired action to be performed on a given resource. Each method communicates a specific intent and they are a fundamental part of the HTTP protocol. Here are the most commonly used HTTP methods:
- GET: This method requests a representation of the specified resource. GET requests should only retrieve data and have no other effect.
- POST: This method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server. For example, posting form data or uploading a file.
- PUT: This method replaces all current representations of the target resource with the request payload. It is used to update a resource or create it if it does not exist.
- DELETE: This method deletes the specified resource.
- HEAD: This method is similar to GET, but it asks for a response identical to that of a GET request, except without the response body. It is useful for retrieving meta-information written in response headers, without having to transport the entire content.
- OPTIONS: This method describes the communication options for the target resource. It can be used to check which HTTP methods are supported by the server.
- PATCH: This method is used to apply partial modifications to a resource. Unlike PUT, PATCH is not idempotent, which means successive identical patch requests may have different effects.
- CONNECT: This method establishes a tunnel to the server identified by the target resource. It is commonly used to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.
- TRACE: This method performs a message loop-back test along the path to the target resource, providing a useful debugging mechanism.
===========================================
|