Fork me on GitHub
#reitit
<
2022-10-18
>
restenb11:10:42

Why would this happen? i just updated reitit router version on an older project that had been gathering dust Error: Router contains conflicting route paths: -> /projects/create -> /projects/:my-project-id

restenb12:10:29

ah, it was in the docs: "Normal path-parameters (`:id`) can start anywhere in the path string, but have to end either to slash / (currently hardcoded) or to an end of path string:"

restenb12:10:37

so just had to add / after :my-project-id

云中客12:10:45

Hello! Can anyone tell me how to use async handler inside ring/router?

(def app
  (ring/ring-handler
    (ring/router
      [["/plus"
        {:get {
               :parameters {:query {:x int?
                                    :y int?}}
               :responses  {200 {:body {:total int?}}}
               :handler
               (fn [{{{:keys [x y]} :query} :parameters} response raise]
                 (response {:status 200
                            :body {:total (+ x y)}}))}}]]

      {:data {:coercion reitit.coercion.spec/coercion
              :muuntaja m/instance
              :middleware [parameters/parameters-middleware
                           rrc/coerce-request-middleware
                           muuntaja/format-response-middleware
                           rrc/coerce-response-middleware]}})))

onetom06:10:01

im not sure what's exactly the problem, but the order of your middlwares might be incorrect, OR that function, which threw the exception, might rely on the presence of other middlewares, which are related to the wrap-format-response. here the order, what's working in our code:

reitit.ring.middleware.parameters/parameters-middleware
                 muuntaja/format-negotiate-middleware
                 muuntaja/format-response-middleware
                 :handle-exception
                 muuntaja/format-request-middleware
                 reitit.ring.coercion/coerce-exceptions-middleware
                 reitit.ring.coercion/coerce-request-middleware
and one of the official examples are just using muuntaja/format-middleware: https://github.com/metosin/reitit/blob/master/examples/ring-example/src/example/server.clj

onetom07:10:20

i'd highly recommend cloning the following repos, so u can quickly navigate their sources: 1. https://github.com/metosin/reitit.git 2. https://github.com/ring-clojure/ring.git 3. https://github.com/metosin/muuntaja.git and maybe u can fire up a repl for them, so u can directly run their tests. using the tests, u can easily see how these building blocks behave in some specific, narrow situtation.

云中客12:10:29

The code above always raise

Execution error (ArityException) at muuntaja.middleware/wrap-format-response$fn (middleware.clj:132).
Wrong number of args (1) passed to: cweb.web/fn--7565