This library provides an easy to use com.stuartsierra/component
component to start up a http-kit
webserver which
can be provided with a handler. The handler then will handle all incoming requests.
To install, add the following to your project :dependencies
:
[de.phenomdevel/component-webserver "1.0.1"]
The code below shows an lightweight example of how you could use this component within your
com.stuartsierra/component
system.
(require '[de.phenomdevel.components.webserver :as webserver])
(require '[com.stuartsierra.component :as c])
;; Could also come from a file or something
(def ^:private config
{:server
{:port 1212}})
;; This might also be a compojure handler
(defn- handler-factory
[context] ;; Holds all dependencies of `webserver` e.g. if you provide a db-pool component
(fn [request]
{:status 200
:body "Hello World"}))
(def !system
(atom
(c/system-map
:server
(webserver/new-webserver (assoc (:server config) :handler-factory handler-factory}))))
(swap! !system c/start)
;; This will start your system with the webserver
Copyright © 2020 Kevin Kaiser
Distributed under the MIT License.