Last active
November 8, 2024 01:22
-
-
Save borkdude/1627f39d072ea05557a324faf5054cf3 to your computer and use it in GitHub Desktop.
Small ring router using core.mach in babashka
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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
There's a little bug if
(:uri req)
is"/"
. You can rewrite it as(vec (rest (str/split "/" #"/")))
.