keeps track of HTTP requests
See also
stub_registry()
and StubRegistry
Other request-registry:
HashCounter
,
request_registry()
Methods
Method print()
print method for the RequestRegistry
class
Method register_request()
Register a request
Examples
x <- RequestRegistry$new()
z1 <- RequestSignature$new("get", "http://scottchamberlain.info")
z2 <- RequestSignature$new("post", "https://httpbin.org/post")
x$register_request(request = z1)
x$register_request(request = z1)
x$register_request(request = z2)
# print method to list requests
x
#> <webmockr request registry>
#> Registered Requests
#> GET: http://scottchamberlain.info was made 2 times
#>
#> POST: https://httpbin.org/post was made 1 times
#>
# more complex requests
w <- RequestSignature$new(
method = "get",
uri = "https:/httpbin.org/get",
options = list(headers = list(`User-Agent` = "foobar", stuff = "things"))
)
w$to_s()
#> [1] "GET: https:/httpbin.org/get with headers {User-Agent: foobar, stuff: things}"
x$register_request(request = w)
x
#> <webmockr request registry>
#> Registered Requests
#> GET: http://scottchamberlain.info was made 2 times
#>
#> POST: https://httpbin.org/post was made 1 times
#>
#> GET: https:/httpbin.org/get with headers {User-Agent: foobar, stuff: things} was made 1 times
#>
# hashes, and number of times each requested
x$request_signatures$hash
#> $`GET: http://scottchamberlain.info`
#> $`GET: http://scottchamberlain.info`$key
#> [1] "GET: http://scottchamberlain.info"
#>
#> $`GET: http://scottchamberlain.info`$sig
#> <RequestSignature>
#> method: GET
#> uri: http://scottchamberlain.info
#>
#> $`GET: http://scottchamberlain.info`$count
#> [1] 2
#>
#>
#> $`POST: https://httpbin.org/post`
#> $`POST: https://httpbin.org/post`$key
#> [1] "POST: https://httpbin.org/post"
#>
#> $`POST: https://httpbin.org/post`$sig
#> <RequestSignature>
#> method: POST
#> uri: https://httpbin.org/post
#>
#> $`POST: https://httpbin.org/post`$count
#> [1] 1
#>
#>
#> $`GET: https:/httpbin.org/get with headers {User-Agent: foobar, stuff: things}`
#> $`GET: https:/httpbin.org/get with headers {User-Agent: foobar, stuff: things}`$key
#> [1] "GET: https:/httpbin.org/get with headers {User-Agent: foobar, stuff: things}"
#>
#> $`GET: https:/httpbin.org/get with headers {User-Agent: foobar, stuff: things}`$sig
#> <RequestSignature>
#> method: GET
#> uri: https:/httpbin.org/get
#> headers:
#> User-Agent: foobar
#> stuff: things
#>
#> $`GET: https:/httpbin.org/get with headers {User-Agent: foobar, stuff: things}`$count
#> [1] 1
#>
#>
# times_executed method
pat <- RequestPattern$new(
method = "get",
uri = "https:/httpbin.org/get",
headers = list(`User-Agent` = "foobar", stuff = "things")
)
pat$to_s()
#> [1] "GET http://https/httpbin.org%2Fget with headers user-agent=\"foobar\", stuff=\"things\""
x$times_executed(pat)
#> [1] 1
z <- RequestPattern$new(method = "get", uri = "http://scottchamberlain.info")
x$times_executed(z)
#> [1] 2
w <- RequestPattern$new(method = "post", uri = "https://httpbin.org/post")
x$times_executed(w)
#> [1] 1
## pattern with no matches - returns 0 (zero)
pat <- RequestPattern$new(
method = "get",
uri = "http://recology.info/"
)
pat$to_s()
#> [1] "GET http://recology.info"
x$times_executed(pat)
#> [1] 0
# reset the request registry
x$reset()