https://github.com/weavejester/ring-jetty-component.git
git clone 'https://github.com/weavejester/ring-jetty-component.git'
(ql:quickload :weavejester.ring-jetty-component)
A component for the standard Ring Jetty adapter, for use in applications that use Stuart Sierra's reloaded workflow.
Add the following dependency to your project.clj
:
[ring-jetty-component "0.3.1"]
Require the library, and the Component library:
(require '[ring.component.jetty :refer [jetty-server]]
'[com.stuartsierra.component :as component])
Then create a server component:
(defn handler [request]
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Hello World"})
(def app
{:handler handler})
(def http-server
(jetty-server {:app app, :port 3000}))
The :app
option can either be a bare map, or another component
record. It must contain the key :handler
.
All other options are passed to the ring to the Ring Jetty adapter,
except for :join?
, which is always false. This guarantees the
component doesn't block the running thread.
This server can be started using component/start
:
(alter-var-root #'http-server component/start)
And stopped with component/stop
:
(alter-var-root #'http-server component/stop)
As with all components, the return value matters. For more information on how to use components, and how they're useful, refer to Stuart Sierra's Component library.
Copyright © 2016 James Reeves
Distributed under the MIT License, the same as Ring.