A component for the Immutant web server. It is an adapter for Immutant web to be used in reloadable applications.
Add the dependency to your project.clj
:
First require the libraries:
(require '[immutant-web-component.core :refer [immutant-web-server]]
'[com.stuartsierra.component :as component])
Then you can create a new Immutant web server component. It wil depend on a Ring
handler component with an :handler
key holding a handler function. Then you
can start and stop it:
(def web-server
(atom (immutant-web-server {:host "localhost" :port "8080"})))
(let [handler-component {:handler (constantly
{:status 200
:body "Just handling business."})}]
(swap! web-server #(assoc % :handler handler-component))
(swap! web-server #(component/start %))
;; Make some requests to localhost:8080
(swap! web-server #(component/stop %)))
Or, you can use it as part of a reloadable system:
(def handler-fn
(constantly {:status 200 :body "I'm still here!"}))
(def system
(component/system-map
:handler {:handler handler-fn}
:server (component/using
(immutant-web-server {:host "localhost" :port "8080"})
[:handler])))
(alter-var-root #'system component/start)
;; do stuff
(alter-var-root #'system component/stop)
Copyright © 2015 ben lamothe
Distributed under the MIT License
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close