# `RelativeUrl`

An address relative to another: `../images/logo.png`, `?page=2`.

Use it for links inside a document. `web.resolve` makes a [`Url`](/docs/types/type-url.md) of one. For a plain path from the root, use [`UrlPath`](/docs/types/type-url-path.md).

## Shape

One value, held as text in one set form, with no parts: `caf%C3%A9.html`.

## Example

```jadpo
RelativeUrl("../images/logo.png")
```

`RelativeUrl(raw)` checks the text, and text that isn't one breaks the `format` rule.

`text.parse(raw, as: RelativeUrl)` reads one from text that comes from outside. Text that isn't one at all fails `malformed`, such as `https://example.com/`, `mailto:someone@example.com` or `a:b`.

## Good to know

- A scheme is refused, so `https://example.com/` is a [`Url`](/docs/types/type-url.md) instead.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it.

## In JSON

A string, in a request, a response or `json.write`:

```json
"../images/logo.png"
"/docs?page=2#intro"
"//cdn.example.com/app.js"
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`RelativeUrl` is in the group Web and network, and has been in Jadpo since 0.1.0.

### Text form

`text.from` writes one standard text form, the same form `text.parse` reads back: `../images/logo.png`, `/docs?page=2#intro` and `//cdn.example.com/app.js`.

### How it is stored

It is stored in one column named for the field, of type `text`. `?sort=name` is stored as `'?sort=name'`.

### How it is shown to people

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

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `../images/logo.png` | `../images/logo.png` |
| `/docs?page=2#intro` | `/docs?page=2#intro` |
| `//cdn.example.com/app.js` | `//cdn.example.com/app.js` |
| `?sort=name` | `?sort=name` |
| `#top` | `#top` |
| `caf%C3%A9.html` | `caf%C3%A9.html` |

### Operations

- `web.resolve(base: Url, relative: RelativeUrl) -> Url`: `relative` resolved against `base` by RFC 3986 (section 5.2): its `.` and `..` segments followed, a path starting `/` taken from the host, a query or a fragment alone kept with the base's path. A `UrlPath` is a `RelativeUrl`, so it resolves too.

It also takes `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
