# Local API

> For the complete documentation index, see [llms.txt](https://docs.ringleader.dev/llms.txt).


> Send one request to the Ringleader API on this computer from a terminal or a script, with the same access every rl command has.


The Ringleader [daemon](https://docs.ringleader.dev/reference/cli/commands/daemon/) on this computer serves Ringleader's API on
a socket that only your user account can open. `rl api` sends one HTTP request to it and prints
the answer, so a script can read or change objects through the API without a token. The daemon
answers with the same access every `rl` command on this computer has.

## Send a request

`rl api` needs a running daemon. The Ringleader desktop application starts one for you, and
`rl daemon start` starts one from a terminal. Then pass an API path. This reads the `local`
namespace, which Ringleader creates on every computer:

```bash
rl api /apis/core.ringleader.dev/v1/namespaces/local
```

```text
{"apiVersion":"core.ringleader.dev/v1","kind":"Namespace","metadata":{"name":"local","uid":"7921f46c-8aa5-47fc-8e67-914a995a1161","resourceVersion":"sostb88sciWM","generation":1,"creationTimestamp":"2026-10-30T19:43:31Z","labels":{"ringleader.dev/reserved":"true"},"annotations":{"orgs.ringleader.dev/org":"local"},"origin":"self"},"spec":{"maxWorkstations":500,"org":"local"}}
```

The body goes to stdout exactly as the API sent it, and `rl api` exits `0`.

To change something, name the method with `-X` and send the body with `--input`. This creates a
[ConfigMap](https://docs.ringleader.dev/reference/resources/configmap/) from a file named `configmap.json`:

```json
{
  "apiVersion": "core.ringleader.dev/v1",
  "kind": "ConfigMap",
  "metadata": {"name": "motd", "namespace": "local"},
  "spec": {"data": {"motd": "Welcome to the team's development box.\n"}}
}
```

```bash
rl api -X POST --input configmap.json /apis/core.ringleader.dev/v1/namespaces/local/configmaps
```

```text
{"apiVersion":"core.ringleader.dev/v1","kind":"ConfigMap","metadata":{"name":"motd","namespace":"local","uid":"99bb93e0-a89e-4ee3-bbed-acaadb314a1b","resourceVersion":"qo1Lb5hxywAw","generation":1,"creationTimestamp":"2026-10-30T19:43:46Z","annotations":{"ringleader.dev/reach-scope":"admin","ringleader.dev/subject":"user:local"},"origin":"self"},"spec":{"data":{"motd":"Welcome to the team's development box.\n"}}}
```

The API answers a create with the object it stored. `rl get configmap motd -n local` now lists it.

If that is all you need, you are done. The rest of this page covers the flags, what a refused
request prints, and who can reach the API.

## Paths and flags

`rl api <path>` takes one API path, with its query string if it has one. The leading `/` is
optional. A full URL such as `https://example.com/apis/...` is refused, so the request goes to the
daemon on this computer and nowhere else.

| Flag | Description |
|------|-------------|
| `-X, --method <method>` | `GET` (the default), `POST`, `PUT`, `PATCH` or `DELETE`, in upper or lower case. |
| `--input <file>` | Send this file as the request body, or `-` to send stdin. `rl api` refuses it with `GET` and `DELETE`, which take no body. |
| `--home <dir>` | Data directory of the daemon to send the request to. |

These examples show the other forms:

```bash
# Send the body from stdin
rl api -X POST --input - /apis/core.ringleader.dev/v1/namespaces/local/configmaps < configmap.json

# Delete the ConfigMap. The answer is the object as it was.
rl api -X DELETE /apis/core.ringleader.dev/v1/namespaces/local/configmaps/motd

# Print each change to the workstations in a namespace, until you press Ctrl-C
rl api /apis/workstations.ringleader.dev/v1/namespaces/local/watch/workstations
```

A watch prints events as they happen and never ends by itself. Pressing Ctrl-C ends it, and
`rl api` exits `0`.

In Git Bash on Windows, leave out the leading `/`. Git Bash rewrites an argument that starts with
`/` into a Windows file path before `rl` sees it:

```bash
rl api apis/core.ringleader.dev/v1/namespaces
```

## Refused requests

When the API answers with anything other than a `2xx` status, `rl api` prints nothing on stdout,
prints one line on stderr and exits `1`. The line names the method, the path, the HTTP status and
the API's own message:

```text
$ rl api /apis/core.ringleader.dev/v1/namespaces/local/configmaps/motd
api: GET /apis/core.ringleader.dev/v1/namespaces/local/configmaps/motd: 404 Not Found: not found
```

`rl api` does not follow a redirect. The line names where the redirect points instead.

A mistake in the command itself exits `2` and sends nothing. That covers a missing path, a full
URL, a method other than the five above, and `--input` with `GET` or `DELETE`:

```text
$ rl api -X HEAD /apis/core.ringleader.dev/v1/namespaces
api: method "HEAD" is not one the API serves. Use GET, POST, PUT, PATCH or DELETE
```

Some changes to a workstation that runs on this computer are accepted only from the `rl` command
itself, which signs them with this computer's key. `rl api` sends them unsigned, so the API
refuses them with `403`. If that happens, make the change with `rl`.

## Unanswered requests

With no daemon running, `rl api` sends nothing, prints this line and exits `1`:

```text
$ rl api /apis/core.ringleader.dev/v1/namespaces
api: no daemon is running for /Users/you/.ringleader. Start one with `rl daemon start`.
```

A daemon that has just started takes a few seconds to open its socket. While the socket is
missing or refuses the connection, `rl api` keeps trying for up to 15 seconds, so a script can
run it straight after `rl daemon start` or `rl daemon restart`. A daemon that is running and
still does not answer after that, for example one started by an older `rl`, makes `rl api`
print a line like this one and exit `1`:

```text
api: the running daemon did not answer on its API socket: dial unix /Users/you/.ringleader/api.sock: connect: no such file or directory. Run `rl daemon restart`. If it fails again, /Users/you/.ringleader/daemon.log says why.
```

Run `rl daemon restart`. If the socket still does not answer, the daemon log the line names says
why. A daemon started with `--store-dsn`, or with `--addr` and `--require-auth`, never serves the
socket, and `rl api` prints the same line for it.

## API access

Only your user account can open the socket. Where it is depends on the operating system:

- On macOS and Linux it is the file `api.sock` in the data directory, so `~/.ringleader/api.sock`
  by default, and only your user can read or write it. If that path would be longer than 100
  bytes, the socket is in a private directory named `rld-` and 12 hex digits instead, under
  `$XDG_RUNTIME_DIR`, or under your user cache directory when that variable is not set.
- On Windows it is a named pipe, `\\.\pipe\ringleader-api-` and 8 hex digits, that only your
  account can open.

On Windows, and for a socket in an `rld-` directory, `rl api` checks that the socket is yours
before it sends anything. If it is not, `rl api` sends nothing, prints this line and exits `1`:

```text
api: the API socket \\.\pipe\ringleader-api-1a2b3c4d is not owned by the current user, so nothing was sent.
```

Every request through the socket has the same access every `rl` command on this computer has, and
no more. A list returns this computer's objects together with those on the Ringleader service you are
signed in to, as `rl get` does.

