Hi, I would like to receive `List<Stirng>` i...
# ktor
d
Hi, I would like to receive
List<Stirng>
in a
GET
request what's the most efficient way to do so? I'm currently doing like this but was hoping if I can receive List<String> without any manual operation
Copy code
val keywords = call.request.queryParameters["keywords"]?.split(',') // List<String>?
GET
url will be like
?keywords=a,b,c
ł
You can try to use Location and set List<String> as a param
d
Sorry I'm quite new and didn't understand what you just said. Can you show some small example or redirect to some doc regrading the same?
ł
👍 1
Do you understand how does it work?
d
Thanks
figuring out
b
Also call.request.queryParameters.getAll("key")
Then you make a request by passing in multiple key=one&key=two...
d
@Big Chungus thanks but wouldn't that make things hefty for the client?
b
Well it's a standard http way of defining areay-like query parameters
1
Plus remember that client will be building query in code, so it can just use loop or map function to prefix stuff with key
d
ok thanks, well then I think I'll go by
getAll
method because I don't I think I should add new plugin just for such a simple use case. right?
👍 1
b
Ktor might even support comma separated params with getAll. Give it a go, I haven't tried it myself that way
d
NO comma separated didn't work, but the way you mentioned worked
👍 2
b
Good to know!
👍 1
m
@Danish Ansari the client, unless is someone using curl or similar, should be using an appropriate library that will abstract away the complexity of building a URL query string