I'm having trouble with ring-handler, idk what i am doing incorrectly here. I keep getting nil from the handler per the docs i expect to be able to run the handler as a fn and get a resolution. Anyone know where i misunderstood? ๐งต
This is what i have tried
(ns dev
(:require
[hiccup2.core :as h]
[reitit.core :as r]
[reitit.ring :as ring]
[ring.adapter.jetty9 :as jetty]
;; [ring.middleware.reload :as reload]
[ring.util.response :as resp]))
(defn ping-pong [_]
(resp/response (str (h/html [:p "pong"]))))
(defn root [r]
(resp/response (:remote-addr r)))
(def routes
["/"
["" {:name ::root
:handler root}]
["ping" {:name ::ping
:handler ping-pong}]]
#_[["/" {:name ::root
:handler root}]
["/ping" {:name ::ping
:handler ping-pong}]])
(def router
(r/router routes))
(comment
(r/match-by-path router "/ping")
;; => #reitit.core.Match{:template "/ping", :data {...}, ...}
(r/match-by-name router ::ping)
;; => #reitit.core.Match{:template "/ping", :data {...}, ...}
)
(def handler
(ring/ring-handler router))
(comment
(handler {:request-method :get :uri "/ping"})
;; => nil
(-> handler
ring/get-router
(r/match-by-path "/ping"))
;; => #reitit.core.Match{:template "/ping", :data {...}, ...}
)you need to use (ring/router routes) instead of (r/router routes) there
oh thank you!
that was so simple, thank you for pointing that out