# shirts
[](https://builds.sr.ht/~mtmn/shirts?)
A URL shortener. Links are stored in a SQLite database and served under a configurable base URL.
## Building
```sh
mix deps.get
mix release
```
## Usage
### Create a short link
```sh
curl -X POST http://localhost:8721/curtail \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/very/long/path"}'
```
Optionally provide a custom code:
```sh
curl -X POST http://localhost:8721/curtail \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/very/long/path", "code": "my-code"}'
```
### List all short links
```sh
curl http://localhost:8721/history \
-H "Authorization: Bearer <token>"
```
Returns a table ordered by creation time. Request JSON instead with an `Accept` header:
```sh
curl http://localhost:8721/history \
-H "Authorization: Bearer <token>" \
-H "Accept: application/json"
```
JSON shape: `{"count": N, "shirts": [{"code": ..., "url": ..., "created_at": ...}]}`.
### Follow a short link
```
GET /s/<code>
```
## Configuration
| Variable | Description |
|------------|--------------------------------------|
| `PORT` | Port to listen on (default: `8721`) |
| `HOST` | Host to bind to (default: `127.0.0.1`) |
| `BASE_URL` | Base URL used when generating links |
| `AUTH_TOKEN` | Bearer token for the create endpoint |
| `DB_PATH` | Path to the SQLite database file |