See https://www.rfc-editor.org/rfc/rfc3986 for details of parsing algorithm.

parse_url(url)

build_url(url)

Arguments

url

Character. For parse_url a character vector (of length 1) to parse into components; for build_url a list of components to turn back into a string.

Value

a list containing:

  • scheme

  • hostname

  • port

  • path

  • item, a list containing dir, file, and extension

  • params

  • fragment

  • query, a list

  • username

  • password

Examples

parse_url("http://google.com/")
#> - url: http://google.com/
#> - scheme: http
#> - hostname: google.com
#> - host_info_name: google
#> - host_info_extension: com
#> - path: 
parse_url("http://google.com:80/")
#> - url: http://google.com:80/
#> - scheme: http
#> - hostname: google.com
#> - host_info_name: google
#> - host_info_extension: com
#> - port: 80
#> - path: 
parse_url("http://google.com:80/?a=1&b=2")
#> - url: http://google.com:80/?a=1&b=2
#> - scheme: http
#> - hostname: google.com
#> - host_info_name: google
#> - host_info_extension: com
#> - port: 80
#> - path: 
#> - query_a: 1
#> - query_b: 2

url <- parse_url("http://google.com/")
url$scheme <- "https"
url$query <- list(q = "hello")
build_url(url)
#> [1] "https://google.com/?q=hello"