This is my app:
(def routes
[["/api"
ping-routes
submissions-routes]])
(def app
(ring/ring-handler
(ring/router routes
{:data {:coercion reitit.coercion.schema/coercion
:muuntaja m/instance
:middleware [[wrap-cors
:access-control-allow-origin [#"http://localhost:4200"]
:access-control-allow-methods [:get :post]]
parameters-middleware
format-negotiate-middleware
format-response-middleware
exception-middleware
format-request-middleware
coerce-exceptions-middleware
coerce-request-middleware
coerce-response-middleware]}})
(ring/routes
(ring/redirect-trailing-slash-handler {:method :strip})
(ring/create-default-handler
{:not-found (constantly {:status 404 :body "Route not found"})}))))
(def ping-routes
["/ping" {:get (fn [req]
{:status 200
:body {:ping "pong"}})}])
(def submissions-routes
["/submissions"
["" {:get get-submissions}]
["/:id" {:get {:parameters {:path {:id s/Int}}
:handler get-submission-by-id}}]])
(comment
(get-submission-by-id {:parameters {:path 20}}))
When I try access "submissions/1 I get "{"type":"exception","class":"clojure.lang.ExceptionInfo"}" in the browser or within the repl:
{:status 500,
:body
#object[java.io.ByteArrayInputStream 0x3db2e139 "java.io.ByteArrayInputStream@3db2e139"],
:headers {"Content-Type" "application/json; charset=utf-8"}}
If I run my comment code then the get-submission-by-id handler works fine on it's own. Thanks in advance.
Try to define your routes more precisely with names and strict structuring, like this:
(def submissions-routes
[["/submissions" {:name ::experiment}
["" {:name ::root-submission-route
:get {:handler (fn [_] {:status 200
:body {:resp "empty get"}})}}]
["/:id" {:name ::root-submission-route-id
:get {:parameters {:path {:id Long}}
:handler (fn [r] {:status 200 :body {:resp (-> r :path-params :id)}})}}]]])