|
1 | 1 | # Duct Handler [](https://github.com/duct-framework/handler/actions/workflows/test.yml) |
2 | 2 |
|
3 | | -A Clojure library designed to ... well, that part is up to you. |
| 3 | +A library that provides common [Ring][] handlers for the [Duct][] |
| 4 | +framework. |
| 5 | + |
| 6 | +[ring]: https://github.com/ring-clojure/ring |
| 7 | +[duct]: https://github.com/duct-framework/duct |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +Add the following dependency to your deps.edn file: |
| 12 | + |
| 13 | + org.duct-framework/handler {:mvn/version "0.1.0-SNAPSHOT"} |
| 14 | + |
| 15 | +Or to your Leiningen project file: |
| 16 | + |
| 17 | + [org.duct-framework/handler "0.1.0-SNAPSHOT"] |
4 | 18 |
|
5 | 19 | ## Usage |
6 | 20 |
|
7 | | -FIXME |
| 21 | +This library provides three [Integrant][] keys that initiate into Ring |
| 22 | +handlers. |
| 23 | + |
| 24 | +`:duct.handler/static` creates a handler that always returns the same |
| 25 | +response map. The value of this key is the response map itself. |
| 26 | + |
| 27 | +`:duct.handler/file` and `:duct.handler/resource` are handlers that |
| 28 | +return files or resources. They take two options: |
| 29 | + |
| 30 | +- `:paths` - a map of paths strings to an option map |
| 31 | +- `:not-found` - a response map to be returned if no path matches |
| 32 | + |
| 33 | +If the `:not-found` option is not supplied, `nil` is returned from the |
| 34 | +handler (which can be useful for trying multiple handlers to see which |
| 35 | +matches). |
| 36 | + |
| 37 | +The options mapped from each path go directly to the |
| 38 | +[ring.util.reponse/file-response][file-resp] and |
| 39 | +[ring.util.response/resource-response][res-resp] functions. |
| 40 | + |
| 41 | +For example: |
| 42 | + |
| 43 | +```edn |
| 44 | +{:duct.handler/file |
| 45 | + {"/" {:root "public"} |
| 46 | + "/js" {:root "target/js"}}} |
| 47 | +``` |
| 48 | + |
| 49 | +[integrant]: https://github.com/weavejester/integrant |
| 50 | +[file-resp]: https://ring-clojure.github.io/ring/ring.util.response.html#var-file-response |
| 51 | +[res-resp]: https://ring-clojure.github.io/ring/ring.util.response.html#var-resource-response |
8 | 52 |
|
9 | 53 | ## License |
10 | 54 |
|
|
0 commit comments