# pijul-srv-lite

Idea & initial code by [toastal](https://toast.al).

## Usage

```
Usage: pijul-srv-lite [OPTIONS] <REMOTE_DIR>

Arguments:
  <REMOTE_DIR>  Directory containing pijul remotes (or a single repository)
                [env: PIJUL_SRV_REMOTE_DIR=]

Options:
      --bind-addr <BIND_ADDR>  Address to bind to [env: PIJUL_SRV_BIND_ADDR=]
                               [default: 127.0.0.1]
      --port <PORT>            Port to listen on [env: PIJUL_SRV_PORT=]
                               [default: 11988]
      --socket <PATH>          Unix domain socket to listen on instead of TCP
                               [env: PIJUL_SRV_SOCKET=]
  -h, --help                   Print help
  -V, --version                Print version
```

Command-line options take precedence over environment variables. Run
`pijul-srv-lite --help` for full usage.

## Goals

- Low resource use
- Minimal (as in LOC)
- Host many remotes from one lightweight process

## Inspecting channel state

`GET /[remote-path/].pijul?current[=channel]` returns the latest state of a
channel as `{position} {merkle} {tag_merkle}` (channel defaults to `main`).
This is the closest equivalent to `git ls-remote` for checking a remote’s
current state hash:

```console
$ curl 'http://localhost:11988/.pijul?current=main'
$ curl 'http://localhost:11988/foo/.pijul?current=main'
$ curl -H 'Accept: application/json' 'http://localhost:11988/.pijul?current=main'
$ curl -H 'Accept: application/edn' 'http://localhost:11988/foo/.pijul?current=main'
```

Responses carry an `ETag`, so polling clients can send `If-None-Match` & get a
cheap `304 Not Modified` when the state has not changed. Server-side, the
pristine database is only re-opened when it actually changes.

## Provenance

toastal had an agent write a rust package since he wasn’t interested in learning
Rust.

[Tetov](https://tetov.se) was irritated by the code & rewrote it.
