Skip to contents

List or clear requests in the request registry

Usage

request_registry()

request_registry_clear()

Value

an object of class RequestRegistry, print method gives the requests in the registry and the number of times each one has been performed

Details

request_registry() lists the requests that have been made that webmockr knows about; request_registry_clear() resets the request registry (removes all recorded requests)

See also

Other request-registry: HashCounter, RequestRegistry

Examples

webmockr::enable()
#> CrulAdapter enabled!
#> HttrAdapter enabled!
stub_request("get", "https://httpbin.org/get") %>%
  to_return(body = "success!", status = 200)
#> <webmockr stub> 
#>   method: get
#>   uri: https://httpbin.org/get
#>   with: 
#>     query: 
#>     body: 
#>     request_headers: 
#>   to_return: 
#>   - status: 200
#>     body: success!
#>     response_headers: 
#>     should_timeout: FALSE
#>     should_raise: FALSE

# nothing in the request registry
request_registry()
#> <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
#> 

# make the request
z <- crul::HttpClient$new(url = "https://httpbin.org")$get("get")

# check the request registry - the request was made 1 time
request_registry()
#> <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
#> 
#>   GET:  https://httpbin.org/get   with headers {Accept-Encoding: gzip, deflate, Accept: application/json, text/xml, application/xml, */*} was made 1 times
#> 

# do the request again
z <- crul::HttpClient$new(url = "https://httpbin.org")$get("get")

# check the request registry - now it's been made 2 times, yay!
request_registry()
#> <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
#> 
#>   GET:  https://httpbin.org/get   with headers {Accept-Encoding: gzip, deflate, Accept: application/json, text/xml, application/xml, */*} was made 2 times
#> 

# clear the request registry
request_registry_clear()
webmockr::disable()
#> CrulAdapter disabled!
#> HttrAdapter disabled!