This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-25
Channels
- # announcements (1)
- # beginners (70)
- # boot (2)
- # cider (12)
- # cljdoc (19)
- # clojure (25)
- # clojure-austin (1)
- # clojure-nl (2)
- # clojure-uk (9)
- # clojurescript (24)
- # cursive (7)
- # datomic (8)
- # figwheel-main (22)
- # flambo (1)
- # fulcro (16)
- # funcool (3)
- # jobs (1)
- # juxt (3)
- # off-topic (39)
- # reagent (4)
- # reitit (4)
- # ring (2)
- # shadow-cljs (90)
- # specter (11)
- # sql (2)
- # testing (2)
merged current status of reitit-http
and reitit-sieppari
into master, for the adventurous: https://github.com/metosin/reitit/tree/master/examples/http
👍 4
(ns example.server
(:require [reitit.http :as http]
[reitit.ring :as ring]
[clojure.core.async :as a]
[reitit.interceptor.sieppari]
[ring.adapter.jetty :as jetty]))
(defn -interceptor [f x]
{:enter (fn [ctx] (f (update-in ctx [:request :via] (fnil conj []) x)))
:leave (fn [ctx] (f (update-in ctx [:response :body] str "\n<- " x)))})
(def interceptor (partial -interceptor identity))
(def future-interceptor (partial -interceptor #(future %)))
(def async-interceptor (partial -interceptor #(a/go %)))
(defn -handler [f {:keys [via]}]
(f {:status 200,
:body (str (apply str (map #(str "-> " % "\n") via)) " hello!")}))
(def handler (partial -handler identity))
(def future-handler (partial -handler #(future %)))
(def async-handler (partial -handler #(a/go %)))
(def app
(http/ring-handler
(http/router
["/api"
{:interceptors [(interceptor :api)]}
["/sync"
{:interceptors [(interceptor :sync)]
:get {:interceptors [(interceptor :hello)]
:handler handler}}]
["/async"
{:interceptors [(async-interceptor :async)]
:get {:interceptors [(async-interceptor :async-hello)]
:handler async-handler}}]
["/future"
{:interceptors [(future-interceptor :sync)]
:get {:interceptors [(future-interceptor :hello)]
:handler future-handler}}]])
(ring/create-default-handler)
{:executor reitit.interceptor.sieppari/executor}))
(defn start []
(jetty/run-jetty #'app {:port 3000, :join? false, :async? true})
(println "server running in port 3000"))
(comment
(start))