From 992210d3edca80df71689065178a2e5a1cfac009 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Tue, 17 Feb 2026 23:03:14 +0200 Subject: Add Jank support --- examples/jank-test-project/src/example/main.jank | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 examples/jank-test-project/src/example/main.jank (limited to 'examples/jank-test-project') diff --git a/examples/jank-test-project/src/example/main.jank b/examples/jank-test-project/src/example/main.jank new file mode 100644 index 0000000..6744b02 --- /dev/null +++ b/examples/jank-test-project/src/example/main.jank @@ -0,0 +1,56 @@ +;; 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!") -- cgit v1.2.3