Learn R Programming

webmockr (version 0.1.0)

UriPattern: UriPattern

Description

UriPattern

Arguments

pattern
(character) a uri, either plain character string or regex, see base::regex. if scheme is missing, it is added (we assume http)

Details

Methods
add_query_params
Add query parameters to the URI - query_params
matches(uri)
Match a uri against that given in pattern - uri (character) a uri, including scheme (i.e., http or https)

Examples

Run this code
# trailing slash
(z <- UriPattern$new(pattern = "http://foobar.com"))
z$matches("http://foobar.com")
z$matches("http://foobar.com/")

# default ports
(z <- UriPattern$new(pattern = "http://foobar.com"))
z$matches("http://foobar.com:80")
z$matches("http://foobar.com:80/")
z$matches("http://foobar.com:443")
z$matches("http://foobar.com:443/")

# user info
(z <- UriPattern$new(pattern = "http://foobar.com"))
z$matches("http://user:pass@foobar.com")

# regex
(z <- UriPattern$new(regex_pattern = ".+ample\\.."))
z$matches("http://sample.org")
z$matches("http://example.com")
z$matches("http://tramples.net")

# add query parameters
(z <- UriPattern$new(pattern = "http://foobar.com"))
z$add_query_params(list(pizza = "cheese", cheese = "cheddar"))
z$pattern

(z <- UriPattern$new(pattern = "http://foobar.com"))
z$add_query_params(list(pizza = "deep dish", cheese = "cheddar"))
z$pattern

Run the code above in your browser using DataLab