Fork me on GitHub
#ring-swagger
<
2016-11-24
>
borkdude15:11:44

Is it possible to send a GET request to compojure-api like this: /foo?terms[0]=a&terms[1]=b and have it destructured as a query param terms of type vector of string?

borkdude15:11:08

else I’m going to just use a POST

borkdude15:11:28

I tried: :query-params [terms :- [s/Str]]

borkdude15:11:56

I get: {”errors":{"terms":"missing-required-key"}}

borkdude15:11:32

This style url seems to work: uris?terms=british&terms=foo

borkdude15:11:55

but cljs-ajax uses the before mentioned style

juhoteperi15:11:58

I think it should work without []

juhoteperi15:11:15

There is no option to change this

juhoteperi15:11:41

Or hmm... I guess you could use custom middleware to strip those [] from query param names

borkdude15:11:57

Maybe I should check cljs-ajax if arrays can be encoded differently

borkdude15:11:12

or do it myself

juhoteperi15:11:23

If I recall correctly, the default middleware will just name the keys in request query-params e.g. :terms[]

ikitommi15:11:15

is there an existing ring-mw for this? in ring repo maybe?

juhoteperi15:11:42

@borkdude try adding :middleware [ring.middleware.nested-params/wrap-nested-params] ...) to your API options

borkdude15:11:06

worth a try

juhoteperi15:11:10

Not sure if that works with [0] and [1] but should work with terms[]

borkdude15:11:24

no sorry, I’m going for POST, this takes too long 🙂

borkdude15:11:38

I ran into problems with the mentioned middleware before

juhoteperi15:11:53

Yeah, that's what we use often if we need complex options 🙂