Fork me on GitHub
#luminus
<
2016-05-07
>
thug.nasty01:05:51

how can I coerce the numeric values sent in a request to come in as numbers and not strings?

thug.nasty02:05:45

@yogthos: hey there, would you happen to know? ^

yogthos04:05:05

@thug.nasty: the best way would be to use compojure-api

yogthos04:05:33

when you specify a parameter as s/Num it will be automatically coerced

thug.nasty17:05:32

@yogthos: would I then add this to my defroutes entry?

clj 
  (POST "/" request
        :params [a :- Num,
                 b :- Num,
                 c :- Num]
        (process-request! request))

yogthos17:05:18

Yeah should look something like that, I believe you have to specify the type of params, e.g: :query-params

plexus20:05:08

In regular compojure you can also do [x :<< as-int] . as-int is defined in compojure.coercions

thug.nasty21:05:42

i have a lot of form parameters that appear in two different maps

thug.nasty21:05:10

if I want to keep the map format, do I destructure it as a map with values of specific types?

thug.nasty21:05:57

also, how do I refer to the request that has had the values coerced?

thug.nasty21:05:41

also, do I need to specify the types of all values in the map, or just the ones I want changed?

thug.nasty21:05:36

I’ve tried creating a schema, and seeing if that worked

thug.nasty21:05:42

I’m obviously doing something wrong

eggsyntax21:05:25

Quick question re: templating: I'm using hiccup, but trying to combine it with selmer in order to take advantage of the generated templates. So I'm writing a fn that lets you substitute html-ized hiccup into your html-ized selmer, using string/replace. The problem is that, having done that, newlines end up rendering as literal \n on the page. Is there some standard luminus/selmer/hiccup way to get around that? Or is it just a Bad Idea to call string functions on the output of (render template)?

eggsyntax22:05:21

Never mind, (s/replace s "\\n" "\n") was sufficient.