plumber
plumber copied to clipboard
Add support for comma separated query parameters
Consider this plumber.R
file:
library(plumber)
#* Sort letters
#* @param letters:[]
#* @json
#* @get /letters
function(letters) {
sort(letters)
}
How do I change the request from this:
http://127.0.0.1:9203/letters?letters=a&letters=b
To this:
http://127.0.0.1:9203/letters?letters=a,b
Swagger docs on parameter serialization: https://swagger.io/docs/specification/serialization/
This currently works for path variables:
#* Sort letters
#* @param letters:[string]
#* @json
#* @get /letters/<letters:[string]>
function(letters) {
sort(letters)
}
(Also adding a note to self for the spec changes in PR #889)
Docs on path variables are in https://www.rplumber.io/articles/routing-and-input.html
Ref : https://community.rstudio.com/t/comma-separated-query-parameters-in-plumber-api/156781/2
Note : Think about issue with number conversion. Comma in values? I remember we played with the idea but decided against it because it created more problems? There might be a smart way to do it that will appear with automated argument conversion.