Fork me on GitHub
#reitit
<
2019-10-15
>
dimovich08:10:34

@hackeryarn Thanks for the suggestion! Reload middleware seems to be reloading the namespaces only on request. But it would be nice to have it reload automatically on file change.

dimovich08:10:33

Also it is using (require <ns> :reload) which will not work properly if you're using a maven or clojars lib, and you're modifying a local copy of it. In this case (load-file ...) would be more appropriate.

joshkh16:10:31

is it possible to use reitit/match-by-name with coercion? i've only seen examples for reitit/match-by-path and some quick tests make me think coercion and match-by-name don't jive.

joshkh16:10:42

for example, :page/num is not coerced to an integer here:

(def my-router
  (reitit/router
    [["/" {:coercion reitit.coercion.spec/coercion}
      ["{page/num}" {:name       :page-num
                     :parameters {:path {:page/num integer?}}}]]]))

(reitit/match-by-name my-router :page-num {:page/num "2"})
=>
#reitit.core.Match
[:template "/{page/num}"]
[:data {...}]
[:result nil]
[:path-params {:page/num "2"}]
[:path "/2"]

ikitommi17:10:41

@joshkh should work, first do the match and then apply the coercion like described in https://cljdoc.org/d/metosin/reitit/0.3.10/doc/coercion/coercion-explained#full-example. Not at computer, so didn't test thou.

ikitommi17:10:00

both match-by-name and match-by-path return same Result, which is the arg for the coercion.

joshkh17:10:40

hmm. i modified the full-example to use Spec coercion, and this time added coercion/coerce! to the resulting Match, but it returns nil:

; with `coercion/coerce!`
(let [test-router (reitit/router
                    ["/:company/users/:user-id" {:name       ::user-view
                                                 :coercion   reitit.coercion.spec/coercion
                                                 :parameters {:path {:company string?
                                                                     :user-id int?}}}])]
  (coercion/coerce! (reitit/match-by-name test-router ::user-view {:company "ECorp" :user-id "666"})))
=>
nil

ikitommi17:10:40

@joshkh hmm.. sorry, can't check that out before Friday, something different in the returned match.

joshkh17:10:30

no worries @ikitommi, i appreciate you taking the time to answer, especially away from a computer 🙂

👍 4
joshkh17:10:55

(for what it's worth the match is a full Match, not a PartialMatch)

ianbishop19:10:44

Is there any way of removing a named middleware from the middleware chain at the handler level?