plumber icon indicating copy to clipboard operation
plumber copied to clipboard

Add support for comma separated query parameters

Open tylerlittlefield opened this issue 2 years ago • 4 comments

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/

tylerlittlefield avatar Jan 06 '23 17:01 tylerlittlefield

This currently works for path variables:


#* Sort letters
#* @param letters:[string]
#* @json
#* @get /letters/<letters:[string]>
function(letters) {
  sort(letters)
}

image

(Also adding a note to self for the spec changes in PR #889)

slodge avatar Jan 12 '23 06:01 slodge

Docs on path variables are in https://www.rplumber.io/articles/routing-and-input.html

slodge avatar Jan 12 '23 06:01 slodge

Ref : https://community.rstudio.com/t/comma-separated-query-parameters-in-plumber-api/156781/2

meztez avatar Nov 20 '23 20:11 meztez

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.

meztez avatar Nov 24 '23 03:11 meztez