The {plumber2} R package recently got released and I'm trying to understand how to leverage an API.
This basic example below works as long as I'm passing only one string without comma in my query.
#* Simply print some strings passed in the query
#*
#* @get /
#*
#* @query mystrings:string
#*
function(query) {
print(query$mystrings)
}
This works : <api_endpoint>/?mystrings=hello
These don't work :
<api_endpoint>/?mystrings=hello&mystrings=world
<api_endpoint>/?mystrings=hello,world
And return the error :
{"type":"https://datatracker.ietf.org/doc/html/rfc9110#section-15.5.1","title":"Bad Request","status":400,"detail":" mystrings must be a scalar value"}
I can read this in the documentation :
Your API may need array-like input from the query string. plumber2 understands two forms of providing array data: Either by providing the same parameter multiple times, e.g. ?arg=1&arg=2&arg=3, or by separating values with a comma, e.g. ?arg=1,2,3.
How can I pass an array of values in my query string so that it can be further interpreted in my API logic ? My case is about asking several ids and then filtering some data with these ids, to then return it to the user.