diff options
| author | Asko Nõmm <asko@nmm.ee> | 2026-02-17 21:08:53 +0000 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2026-02-17 21:08:53 +0000 |
| commit | d9f8ef25050f97061a867d490f0169c636e5d0ca (patch) | |
| tree | ebb9ea0b4581ff75db7e28c2150983408869f4cc /examples/jank-test-project/src | |
| parent | a03d592ed88854aee6ca130e64cdf8388534c5a3 (diff) | |
| parent | 66043d4f32ad371a9b7e61f76f2c8349acce3b16 (diff) | |
Merge pull request 'jank-support' (#2) from jank-support into masterv2.1.0
Reviewed-on: https://git.nmm.ee/asko/ruuter/pulls/2
Diffstat (limited to 'examples/jank-test-project/src')
| -rw-r--r-- | examples/jank-test-project/src/example/main.jank | 56 |
1 files changed, 56 insertions, 0 deletions
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!") |
