# NOT RUN {
if (interactive()) {
# load webmockr
library(webmockr)
library(crul)
URL <- "https://httpbin.org"
# turn on mocking
crul::mock()
# stub a request
stub_request("get", file.path(URL, "get"))
webmockr:::webmockr_stub_registry
# create an HTTP client
(x <- HttpClient$new(url = URL))
# make a request - matches stub - no real request made
x$get('get')
# allow net connect
webmockr::webmockr_allow_net_connect()
x$get('get', query = list(foo = "bar"))
webmockr::webmockr_disable_net_connect()
x$get('get', query = list(foo = "bar"))
}
# }
Run the code above in your browser using DataLab