Learn R Programming

webmockr (version 0.1.0)

RequestPattern: RequestPattern class

Description

RequestPattern class

Arguments

method
the HTTP method (any, head, options, get, post, put, patch, trace, or delete). "any" matches any HTTP method. required.
uri
(character) request URI. required or uri_regex
uri_regex
(character) request URI as regex. required or uri
query
(list) query parameters, optional
body
(list) body request, optional
headers
(list) headers, optional

Details

Methods
matches(request_signature)
Test if request_signature matches a pattern - request_signature: a request signature
to_s()
Print pattern for easy human consumption

See Also

pattern classes for HTTP method MethodPattern, headers HeadersPattern, body BodyPattern, and URI/URL UriPattern

Examples

Run this code
## Not run: ------------------------------------
# (x <- RequestPattern$new(method = "get", uri = "https://httpbin.org/get"))
# x$body_pattern
# x$headers_pattern
# x$method_pattern
# x$uri_pattern
# x$to_s()
# 
# # make a request signature
# rs <- RequestSignature$new(method = "get", uri = "https://httpbin.org/get")
# 
# # check if it matches
# x$matches(rs)
# 
# # regex uri
# (x <- RequestPattern$new(method = "get", uri_regex = ".+ossref.org"))
# x$uri_pattern
# x$uri_pattern$to_s()
# x$to_s()
# 
# # uri with query parameters
# (x <- RequestPattern$new(
#     method = "get", uri = "https://httpbin.org/get",
#     query = list(foo = "bar")
# ))
# x$to_s()
## ---------------------------------------------

Run the code above in your browser using DataLab