;; Minimal Jank example using Ruuter for HTTP routing. ;; ;; Run with: ;; jank run --module-path ../../src:src src/example/main.jank ;; ;; (from the examples/jank-test-project/ directory) (require '[ruuter.core :as ruuter]) (println "Ruuter on Jank - Example") (println "========================") (println "") ;; Define routes (def routes [{:path "/" :method :get :response {:status 200 :body "Welcome home!"}} {:path "/hello/:name" :method :get :response (fn [req] {:status 200 :body (str "Hello, " (get-in req [:params :name]) "!")})} {:path "/api/users/:id" :method :get :response (fn [req] {:status 200 :body (str "User #" (get-in req [:params :id]))})} {:path "/files/:path*" :method :get :response (fn [req] {:status 200 :body (str "File: " (get-in req [:params :path]))})} {:path :not-found :response {:status 404 :body "Page not found."}}]) ;; Simulate HTTP requests (defn simulate [method uri] (let [resp (ruuter/route routes {:uri uri :request-method method})] (println (str " " (name method) " " uri " -> " (:status resp) " " (:body resp))))) (println "Simulating requests:") (println "") (simulate :get "/") (simulate :get "/hello/jank") (simulate :get "/api/users/42") (simulate :get "/files/docs/readme.txt") (simulate :get "/nonexistent") (simulate :post "/hello/world") (println "") (println "Done!")