Build and parse URLs

url_build(url, path = NULL, query = NULL)

url_parse(url)

Arguments

url

(character) a url, length 1

path

(character) a path, length 1

query

(list) a named list of query parameters

Value

url_build returns a character string URL; url_parse returns a list with URL components

Examples

url_build("https://httpbin.org")
#> [1] "https://httpbin.org/"
url_build("https://httpbin.org", "get")
#> [1] "https://httpbin.org/get"
url_build("https://httpbin.org", "post")
#> [1] "https://httpbin.org/post"
url_build("https://httpbin.org", "get", list(foo = "bar"))
#> [1] "https://httpbin.org/get?foo=bar"
url_parse("httpbin.org")
#> $scheme #> [1] NA #> #> $domain #> [1] "httpbin.org" #> #> $port #> [1] NA #> #> $path #> [1] NA #> #> $parameter #> [1] NA #> #> $fragment #> [1] NA #>
url_parse("http://httpbin.org")
#> $scheme #> [1] "http" #> #> $domain #> [1] "httpbin.org" #> #> $port #> [1] NA #> #> $path #> [1] NA #> #> $parameter #> [1] NA #> #> $fragment #> [1] NA #>
url_parse(url = "https://httpbin.org")
#> $scheme #> [1] "https" #> #> $domain #> [1] "httpbin.org" #> #> $port #> [1] NA #> #> $path #> [1] NA #> #> $parameter #> [1] NA #> #> $fragment #> [1] NA #>
url_parse("https://httpbin.org/get")
#> $scheme #> [1] "https" #> #> $domain #> [1] "httpbin.org" #> #> $port #> [1] NA #> #> $path #> [1] "get" #> #> $parameter #> [1] NA #> #> $fragment #> [1] NA #>
url_parse("https://httpbin.org/get?foo=bar")
#> $scheme #> [1] "https" #> #> $domain #> [1] "httpbin.org" #> #> $port #> [1] NA #> #> $path #> [1] "get" #> #> $parameter #> $parameter$foo #> [1] "bar" #> #> #> $fragment #> [1] NA #>
url_parse("https://httpbin.org/get?foo=bar&stuff=things")
#> $scheme #> [1] "https" #> #> $domain #> [1] "httpbin.org" #> #> $port #> [1] NA #> #> $path #> [1] "get" #> #> $parameter #> $parameter$foo #> [1] "bar" #> #> $parameter$stuff #> [1] "things" #> #> #> $fragment #> [1] NA #>
url_parse("https://httpbin.org/get?foo=bar&stuff=things[]")
#> $scheme #> [1] "https" #> #> $domain #> [1] "httpbin.org" #> #> $port #> [1] NA #> #> $path #> [1] "get" #> #> $parameter #> $parameter$foo #> [1] "bar" #> #> $parameter$stuff #> [1] "things[]" #> #> #> $fragment #> [1] NA #>