Skip to content

pass multi-value parameters as vectors to GET #350

@mkoohafkan

Description

@mkoohafkan

GET requests can handle multi-value parameters, although there is no defined standard on how to do it. httr2 currently supports multi-value parameters when you define them explicitly as separate arguments:

request("example.com") |>
  req_url_query(foo = 1, foo = 2) |>
  req_dry_run()

#> GET /?foo=1&foo=2 HTTP/1.1
#> Host: example.com?foo=1&foo=2
#> User-Agent: httr2/0.2.3 r-curl/5.1.0 libcurl/8.3.0
#> Accept: */*
#> Accept-Encoding: deflate, gzip

But it would be nice if you could pass multi-value parameters as vectors and have httr2 do the work of forming the url with multiple entries for the parameter(s):

# desired  behaviour
request("example.com") |>
  req_url_query(foo = c(1, 2)) |>
  req_dry_run()

#> GET /?foo=1&foo=2 HTTP/1.1
#> Host: example.com?foo=1&foo=2
#> User-Agent: httr2/0.2.3 r-curl/5.1.0 libcurl/8.3.0
#> Accept: */*
#> Accept-Encoding: deflate, gzip

I could see the other common form of multi-value parameters being handled via I():

# desired  behaviour
request("example.com") |>
  req_url_query(foo = I(c(1, 2))) |>
  req_dry_run()

#> GET /?foo=1,2 HTTP/1.1
#> Host: example.com?foo=1,2
#> User-Agent: httr2/0.2.3 r-curl/5.1.0 libcurl/8.3.0
#> Accept: */*
#> Accept-Encoding: deflate, gzip

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions