# HTTP Protocol

The HTTP (HyperText Transfer Protocol) protocol is a foundational technology for the web, enabling communication between web browsers and servers. Here are the key aspects of HTTP:

#### Basics

1. **Protocol**: HTTP is a protocol, which is a set of rules for communication. It defines how messages are formatted and transmitted, and how web servers and browsers should respond to various commands.
2. **Client-Server Model**: HTTP operates based on a client-server model. The client, usually a web browser, sends a request to the server, which then processes the request and sends back a response.

#### Components

1. **URL (Uniform Resource Locator)**: The address used to access resources on the web. For example, `http://www.example.com`.
2. **Request Methods**: Methods indicating the desired action to be performed for a given resource. Common methods include:
   * `GET`: Requests data from a specified resource.
   * `POST`: Submits data to be processed to a specified resource.
   * `PUT`: Updates a current resource with new data.
   * `DELETE`: Removes a specified resource.
   * `HEAD`: Similar to GET, but retrieves only the headers and not the body of the response.
3. **Headers**: Key-value pairs sent in both requests and responses, providing metadata such as content type, length, encoding, and more.
4. **Body**: The main content of the request or response, used to transmit data like HTML, JSON, or files.

#### Process

1. **Request**: The client (browser) sends an HTTP request to the server, which includes:
   * The HTTP method.
   * The URL of the resource.
   * HTTP headers.
   * (Optional) A message body.
2. **Response**: The server processes the request and sends back an HTTP response, which includes:
   * A status line (e.g., `HTTP/1.1 200 OK`).
   * HTTP headers.
   * (Optional) A message body with the requested content or error information.

#### Status Codes

HTTP status codes indicate the result of the request. They are grouped into categories:

1. **1xx**: Informational responses (e.g., `100 Continue`).
2. **2xx**: Success (e.g., `200 OK`, `201 Created`).
3. **3xx**: Redirection (e.g., `301 Moved Permanently`, `302 Found`).
4. **4xx**: Client errors (e.g., `404 Not Found`, `403 Forbidden`).
5. **5xx**: Server errors (e.g., `500 Internal Server Error`, `503 Service Unavailable`).

#### Versions

1. **HTTP/1.0**: The original version, simple but with limitations like lack of persistent connections.
2. **HTTP/1.1**: Introduced persistent connections, chunked transfer encoding, and additional cache control mechanisms.
3. **HTTP/2**: Improved performance with features like multiplexing, header compression, and server push.
4. **HTTP/3**: Builds on HTTP/2 and uses QUIC, a transport protocol that improves latency and connection reliability.

HTTP is a stateless protocol, meaning each request from a client to server is independent, and neither the client nor the server retains session information between requests. This characteristic can be managed through mechanisms like cookies, sessions, and tokens to maintain stateful interactions.

{% embed url="<https://www.youtube.com/watch?v=P6SZLcGE4us>" %}
Network Protocols
{% endembed %}

{% embed url="<https://www.youtube.com/watch?v=iYM2zFP3Zn0>" %}
HTTP Protocols
{% endembed %}

{% embed url="<https://www.youtube.com/watch?v=2JYT5f2isg4>" %}
REST API with Javascript
{% endembed %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.jwc.in.th/programming-major/intermediate-website-development/http-protocol.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
