url_parse()
parses a URL into its component pieces; url_build()
does
the reverse, converting a list of pieces into a string URL. See RFC 3986
for the details of the parsing algorithm.
Value
url_build()
returns a string.url_parse()
returns a URL: a S3 list with classhttr2_url
and elementsscheme
,hostname
,port
,path
,fragment
,query
,username
,password
.
Examples
url_parse("http://google.com/")
#> <httr2_url> http://google.com/
#> • scheme: http
#> • hostname: google.com
#> • path: /
url_parse("http://google.com:80/")
#> <httr2_url> http://google.com:80/
#> • scheme: http
#> • hostname: google.com
#> • port: 80
#> • path: /
url_parse("http://google.com:80/?a=1&b=2")
#> <httr2_url> http://google.com:80/?a=1&b=2
#> • scheme: http
#> • hostname: google.com
#> • port: 80
#> • path: /
#> • query:
#> • a: 1
#> • b: 2
url_parse("http://username@google.com:80/path;test?a=1&b=2#40")
#> <httr2_url> http://username@google.com:80/path;test?a=1&b=2#40
#> • scheme: http
#> • hostname: google.com
#> • username: username
#> • port: 80
#> • path: /path;test
#> • query:
#> • a: 1
#> • b: 2
#> • fragment: 40
url <- url_parse("http://google.com/")
url$port <- 80
url$hostname <- "example.com"
url$query <- list(a = 1, b = 2, c = 3)
url_build(url)
#> [1] "http://example.com:80/?a=1&b=2&c=3"