https://github.com/instantwebsite/cawdy
Clojure library for interacting with the Caddy Admin API over HTTP
https://github.com/instantwebsite/cawdy
caddy caddy-server caddy2 caddyserver clojure library
Last synced: 3 months ago
JSON representation
Clojure library for interacting with the Caddy Admin API over HTTP
- Host: GitHub
- URL: https://github.com/instantwebsite/cawdy
- Owner: instantwebsite
- License: mit
- Created: 2020-10-13T17:25:47.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-17T11:43:03.000Z (over 5 years ago)
- Last Synced: 2026-01-14T07:38:47.256Z (5 months ago)
- Topics: caddy, caddy-server, caddy2, caddyserver, clojure, library
- Language: Clojure
- Homepage:
- Size: 35.2 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# cawdy
[](https://clojars.org/cawdy)
[](https://circleci.com/gh/victorb/cawdy/tree/master)
Clojure library for interacting with Caddy via the HTTP Admin API
Tested with Caddy v2.2.1
## Installation
### Leiningen
```
[cawdy "0.3.1"]
```
### deps.edn
```
cawdy {:mvn/version "0.3.1"}
```
## Usage
### Quickstart
Creates a new server that listens on :2015 and serves two domains. One that
gives a static response (`:static`) for all requests and one that serves files
from a directory (`:files`)
```clojure
(require '[cawdy.core :as cawdy])
(def conn (cawdy/connect "http://localhost:2019")
(cawdy/create-server conn {:listen [":2015"]})
(cawdy/add-route conn :my-id "cawdy-response.example" :static {:body "hello"}))
(cawdy/add-route conn :my-id "cawdy-files.example" :files {:root "/etc"}))
```
### Connect to running Caddy server
```clojure
(require '[cawdy.core :as cawdy])
(def conn (cawdy/connect "http://localhost:2019")
```
### Get Current Configuration
```clojure
(cawdy/config conn)
=> {:apps
{:http
{:servers
{:my-id
{:listen ["localhost:2016"],
:routes
[{:handle
[{:handler "file_server", :root "/tmp/cawdytest2"}]}]}}}}})
```
### Add Static Response Handler
```clojure
(cawdy/create-server conn {:listen [":2019"]})
(cawdy/add-route conn :my-id "localhost" :static {:body "This gets returned"}))
```
```shellsession
$ curl --silent localhost:2019
This gets returned
```
Options for :static handler can be:
- `:body` - What to send in the response body
### Add File Server Handler
```clojure
(cawdy/create-server conn {:listen [":2020"]})
(cawdy/add-route conn :my-id "localhost" :static {:root "/etc"}))
```
```shellsession
$ curl --silent localhost:2020/hosts
# Static table lookup for hostnames.
...
```
Options for :files handler are:
- `:root` - What directory should act as the root directory
## Tests
Run tests with `make test` that will automatically download a compatible
Caddy version to run the tests with. It'll also start caddy with no config,
and turn it off after the tests.
Don't run the tests with a caddy instance whos config is important as the
tests will remove the existing config before each test.
## License
Copyright © 2020 Victor Bjelkholm under MIT license, see `LICENSE`