url_query_parse: Parse query parameters and/or build a string

View source: R/url.R

url_query_parseR Documentation

Parse query parameters and/or build a string

Description

url_query_parse() parses a query string into a named list; url_query_build() builds a query string from a named list.

Usage

url_query_parse(query)

url_query_build(query, .multi = c("error", "comma", "pipe", "explode"))

Arguments

query

A string, when parsing; a named list when building.

.multi

Controls what happens when a value is a vector:

  • "error", the default, throws an error.

  • "comma", separates values with a ⁠,⁠, e.g. ⁠?x=1,2⁠.

  • "pipe", separates values with a |, e.g. ?x=1|2.

  • "explode", turns each element into its own parameter, e.g. ?x=1&x=2

If none of these options work for your needs, you can instead supply a function that takes a character vector of argument values and returns a a single string.

Examples

str(url_query_parse("a=1&b=2"))

url_query_build(list(x = 1, y = "z"))
url_query_build(list(x = 1, y = 1:2), .multi = "explode")

r-lib/httr2 documentation built on Jan. 11, 2025, 10:21 a.m.