A component for the standard Ring Jetty adapter
Clojure
Latest commit 87ac67e Jun 13, 2016 @weavejester committed on GitHub Merge pull request #4 from dpassen1/ring-1.5
Upgrade Ring-Jetty-Adapter to 1.5.0

README.md

Ring-Jetty-Component

A component for the standard Ring Jetty adapter, for use in applications that use Stuart Sierra's reloaded workflow.

Installation

Add the following dependency to your project.clj:

[ring-jetty-component "0.3.1"]

Usage

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.

License

Copyright © 2016 James Reeves

Distributed under the MIT License, the same as Ring.