> For the complete documentation index, see [llms.txt](https://dailyjournal.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dailyjournal.gitbook.io/notes/topics/osi-model/http.md).

# HTTP

* HTTP is an **application-layer** protocol for transmitting hypermedia documents, such as HTML.&#x20;
* HTTP follows a classical **client-server model**, with a client opening a connection to make a request, then waiting until it receives a response from the server.&#x20;
* HTTP is a **stateless protocol**, meaning that the server does not keep any data (state) between two requests.

{% embed url="<https://developer.mozilla.org/en-US/docs/Web/HTTP>" %}

## HTTP headers

> let the client and the server pass additional information with an HTTP request or response

* **Request headers** - contain more information about the resource to be fetched, or about the client requesting the resource.
* **Response headers** - hold additional information about the response, like its location or about the server providing it.
* **Representation headers** - contain information about the body of the resource, like its MIME type, or encoding/compression applied.
* **Payload headers** - contain representation-independent information about payload data, including content length and the encoding used for transport.

{% embed url="<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers>" %}

## HTTP request methods

> indicate the desired action to be performed for a given resource

{% hint style="info" %}
Although they can also be nouns, these request methods are sometimes referred to as ***HTTP verbs***.&#x20;
{% endhint %}

<table><thead><tr><th width="116">Verbs</th><th>Description</th></tr></thead><tbody><tr><td><code>GET</code></td><td>The <code>GET</code> method requests a representation of the specified resource. Requests using <code>GET</code> should only retrieve data.</td></tr><tr><td><code>POST</code></td><td>The <code>POST</code> method submits an entity to the specified resource, often causing a change in state on the server.</td></tr><tr><td><code>PUT</code></td><td>The <code>PUT</code> method replaces all current representations of the target resource with the request payload.</td></tr><tr><td><code>DELETE</code></td><td>The <code>DELETE</code> method deletes the specified resource.</td></tr><tr><td><code>PATCH</code></td><td>The <code>PATCH</code> method applies partial modifications to a resource.</td></tr></tbody></table>

> All safe[^1] methods are idempotent[^2], as well as `PUT` and `DELETE`. The `POST` method is not idempotent.

{% embed url="<https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods>" %}

## HTTP response status codes

> indicate whether a specific HTTP request has been successfully completed

| Class | Codes | Description            |
| :---: | :---: | ---------------------- |
|  1xx  |       | Information reponses   |
|  2xx  |       | Successful responses   |
|       |  200  | OK                     |
|       |  201  | Created                |
|       |  204  | No Content             |
|       |  205  | Reset Content          |
|  3xx  |       | Redirection messages   |
|       |  300  | Multiple Choices       |
|       |  301  | Moved Permanently      |
|       |  302  | Found                  |
|  4xx  |       | Client-error responses |
|       |  400  | Bad Request            |
|       |  401  | Unauthorized           |
|       |  403  | Forbidden              |
|       |  404  | Not Found              |
|       |  429  | Too Many Requests      |
|  5xx  |       | Server-error responses |
|       |  500  | Internal Server Error  |
|       |  502  | Bad Gateway            |
|       |  503  | Service Unavailable    |
|       |  504  | Gateway Timeout        |

{% embed url="<https://developer.mozilla.org/en-US/docs/Web/HTTP/Status>" %}

[^1]: An HTTP method is **safe** if it doesn't alter the state of the server. In other words, a method is safe if it leads to a read-only operation. Several common HTTP methods are safe: `GET`, `HEAD`, or `OPTIONS`.

[^2]: An HTTP method is **idempotent** if the intended effect on the server of making a single request is the same as the effect of making several identical requests.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://dailyjournal.gitbook.io/notes/topics/osi-model/http.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
