diff options
| author | Asko Nõmm <asko@bien.ee> | 2021-10-02 23:47:18 -0300 |
|---|---|---|
| committer | Asko Nõmm <asko@bien.ee> | 2021-10-02 23:47:18 -0300 |
| commit | 3003d24e35988981f49db70b446302d7b657df35 (patch) | |
| tree | eab8a18f0c7524a33180e784f307f14062a6130c | |
| parent | d9fa668843527f688e55de6ae2a3ed87db8d80c8 (diff) | |
Add example for Ring + Jetty
| -rw-r--r-- | README.md | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -57,6 +57,31 @@ Now, obviously on its own the router is not very useful as it needs an actual HT (http/run-server #(ruuter/route routes %) {:port 8080})) ``` +### Setting up with [Ring + Jetty](https://github.com/ring-clojure/ring) + +[Ring + Jetty](https://github.com/ring-clojure/ring) set-up is almost identical to the one of http-kit, and looks like this: + +```clojure +(ns myapp.core + (:require [ruuter.core :as ruuter] + [ring.adapter.jetty :as jetty])) + +; The given request map (second argument) will match the +; first route in this example, and return its response. +(def routes [{:path "/" + :method :get + :response {:status 200 + :body "Hi there!"}} + {:path "/hello/:who" + :method :get + :response (fn [req] + {:status 200 + :body (str "Hello, " (:who (:params req)))})}]) + +(defn -main [] + (jetty/run-jetty #(ruuter/route routes %) {:port 8080})) +``` + ### Creating routes Like mentioned above, each route is a map inside of a vector - the order is important only in that the route matcher will return the first result it finds according to `:path`. |
