# `Cookie`

A cookie as a server sets it (RFC 6265 and RFC 6265bis's `SameSite`): its name and value, then its attributes after `; ` in the RFC's order and spelling, `SID=31d4d96e; Path=/; Secure; HttpOnly`. Personal data.

[Web and network](types.md#web-and-network); not ordered; personal data (online); since Jadpo 0.1.0.

## Make one

Build one from its text, `Cookie("lang=en-GB")`, which checks it: text that isn't one breaks `format`.

`text.parse(raw, as: Cookie)` reads one from its text; text that isn't one at all fails `malformed`, such as `SID=31d4 d96e`, `SID=31d4d96e; secure` or `SID=31d4d96e; HttpOnly; Secure`.

## Text, JSON and storage

`text.from` writes its canonical text, the one form `text.parse` reads back. JSON sends its canonical text as a string.

| Text | JSON |
|---|---|
| `lang=en-GB` | `"lang=en-GB"` |
| `SID=31d4d96e407aad42; Path=/; Secure; HttpOnly; SameSite=Lax` | `"SID=31d4d96e407aad42; Path=/; Secure; HttpOnly; SameSite=Lax"` |
| `lang=en-US; Expires=Wed, 21 Oct 2026 07:28:00 GMT; Domain=example.com` | `"lang=en-US; Expires=Wed, 21 Oct 2026 07:28:00 GMT; Domain=example.com"` |
| `__Host-SID=31d4d96e407aad42; Max-Age=3600; Path=/; Secure; SameSite=None` | `"__Host-SID=31d4d96e407aad42; Max-Age=3600; Path=/; Secure; SameSite=None"` |

It is stored in one column named for the field, of type `text`. `lang=en-US; Expires=Wed, 21 Oct 2026 07:28:00 GMT; Domain=example.com` is stored as `'lang=en-US; Expires=Wed, 21 Oct 2026 07:28:00 GMT; Domain=example.com'`.

## Shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `lang=en-GB` | `lang=en-GB` |
| `SID=31d4d96e407aad42; Path=/; Secure; HttpOnly; SameSite=Lax` | `SID=31d4d96e407aad42; Path=/; Secure; HttpOnly; SameSite=Lax` |
| `lang=en-US; Expires=Wed, 21 Oct 2026 07:28:00 GMT; Domain=example.com` | `lang=en-US; Expires=Wed, 21 Oct 2026 07:28:00 GMT; Domain=example.com` |
| `__Host-SID=31d4d96e407aad42; Max-Age=3600; Path=/; Secure; SameSite=None` | `__Host-SID=31d4d96e407aad42; Max-Age=3600; Path=/; Secure; SameSite=None` |

## Operations

It has the contract's own operations: `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
