reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
Janne Sauvala 2021-04-05T21:16:06.040500Z

Hi πŸ‘‹:skin-tone-2: can reitit validate parameter values specified by spec or malli? Is it possible to tell that the parameter should be int and also between values x and y? Or is this something that the handler needs to take care of? I know it can coerce the parameter to the type int but how about the later part πŸ™‚

ikitommi 2021-04-06T13:36:29.045600Z

hi. sure you can, for example with malli you can say [:int {:min 1, :max 100}].

ikitommi 2021-04-06T13:37:00.045800Z

or [:and :int [:fn (fn [x] (>= 1 x 100)]]

ikitommi 2021-04-06T13:37:55.046Z

with spec i recall it’s: (s/int-in 1 100)

Janne Sauvala 2021-04-06T14:35:51.046900Z

That worked beautifully! This reduces the amount of boilerplate code I need to write πŸ™‚

Janne Sauvala 2021-04-06T14:37:38.047100Z

My mistake was that I tried to use the validation like I saw it in the examples in Malli repo: {:path [:map [:quiz [:and int? [:> 6]]] [:option int?]]}. I think it worked somehow but the output error wasn’t so beautiful:

...
"message": "unknown error",
      "schema": "[:> 6]",
      "type": null,
      "value": 1,
      "in": [
        "quiz"
      ]
...

WonderLastking 2021-04-06T15:30:52.047500Z

I also trying to validate form-params, but it seems I cannot make it work. May you have any examples?

ikitommi 2021-04-06T15:46:40.047700Z

Have you looked at the tests @wonderlastking?

WonderLastking 2021-04-07T06:36:39.065700Z

wow, thanks again ikitommi! No I didn't check them. I will now πŸ™‚

wombawomba 2021-04-05T23:56:06.042Z

Is there a way to make reitit.frontend.history not URL-encode a specific path parameter? I have a route like /foo/*bar, and I want to be able to use it to link to URLs like /foo/bar/baz.