A component for the standard Ring Jetty adapter
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
resources
src/ring/component
test/ring/component
.gitignore
README.md
project.clj

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.