summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsko Nõmm <asko@bien.ee>2021-10-02 23:47:18 -0300
committerAsko Nõmm <asko@bien.ee>2021-10-02 23:47:18 -0300
commit3003d24e35988981f49db70b446302d7b657df35 (patch)
treeeab8a18f0c7524a33180e784f307f14062a6130c
parentd9fa668843527f688e55de6ae2a3ed87db8d80c8 (diff)
Add example for Ring + Jetty
-rw-r--r--README.md25
1 files changed, 25 insertions, 0 deletions
diff --git a/README.md b/README.md
index b9729a6..b96fe43 100644
--- a/README.md
+++ b/README.md
@@ -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`.