Skip to content

Instantly share code, notes, and snippets.

@metacritical
Forked from borkdude/router.clj
Created May 27, 2021 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metacritical/4f72e2623c035c645487f5698a5b0ad6 to your computer and use it in GitHub Desktop.
Save metacritical/4f72e2623c035c645487f5698a5b0ad6 to your computer and use it in GitHub Desktop.
Small ring router using core.mach in babashka
(require '[clojure.core.match :refer [match]]
'[clojure.string :as str]
'[hiccup2.core :refer [html]]
'[org.httpkit.server :as server])
(defn router [req]
(let [paths (vec (rest (str/split (:uri req) #"/")))]
(match [(:request-method req) paths]
[:get ["users" id]] {:body (str (html [:div id]))}
:else {:body (str (html [:html "Welcome!"]))})))
(server/run-server router {:port 8090})
@(promise)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment