> ## Documentation Index
> Fetch the complete documentation index at: https://developers.luccasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HTTP Cache

> Learn how to take advantage of the HTTP cache to reduce bandwidth.

## ETag HTTP Header

**Most API endpoints implement HTTP caching.**

This means most responses to GET requests contain an `ETag` header that identifies the specific version of a resource. Each time the corresponding resource changes, a new ETag is generated. As such, comparing ETags indicates whether the representation of a resource has changed.

```http theme={null}
Etag: W/"<etag_value>"
```

Example:

```http theme={null}
Etag: W/"45cdx4"
```

<Info>
  ETags are prefixed with the "W/" characters to indicate that a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests#weak_validation" target="_blank">weak validator</a> is used.
</Info>

***

## Conditional Requests

HTTP Request Headers can give you the ability to issue conditional requests, depending on the current version of the resource. This gives you the ability to prevent "lost update" problems.

* `If-Match: <etag_value> || W/"<etag_value>`: Requests only succeeds if the latest version exactly matches the given ETag value.
* `If-None-Match: <etag_value> || W/"<etag_value>`: Request only succeeds if the latest version does not match the given Etag value.

If the condition is not met, then the server will respond with either a `304 Not Modified` or a `412 Precondition Failed` HTTP status code response (examples below).

The `If-Match` HTTP Header can be used on write requests (POST, PUT, PATCH, DELETE) in order to only apply them if the resource was not changed by someone else since it was retrieved.

```http theme={null}
> Request
PATCH /lucca-api/leaves/123 HTTPS/1.1
Host: example.ilucca.net
Authorization: Bearer <ACCESS_TOKEN>
Api-Version: <API_VERSION>
Accept: application/json
Content-Type: application/json
If-Match: W/"sd457dx1"

{ ... }

< Response
HTTPS/1.1 412 Precondition Failed
ETag: W/"sd457dx1"
Content-Length: 0
```

The `If-None-Match` HTTP Header can be used on read requests (GET, HEAD) in order to only retrieve the representation of the resource if it has changed since the last time it was retrieved.

```http theme={null}
> Request
GET /lucca-api/leaves/123 HTTPS/1.1
Host: example.ilucca.net
Authorization: Bearer <ACCESS_TOKEN>
Api-Version: <API_VERSION>
Content-Type: application/json
If-None-Match: W/"sd457dx1"

< Response
HTTPS/1.1 304 Not Modified
ETag: W/"sd457dx1"
Content-Length: 0
```
