if (FALSE) { # interactive()
# stops with error if no stub and request
request_registry_clear()
stub_registry_clear()
stub_body_diff()
# Gives diff when there's a stub and request found - however, no request body
stub_request("get", "https://hb.opencpu.org/get")
enable()
library(crul)
HttpClient$new("https://hb.opencpu.org")$get(path = "get")
stub_body_diff()
# Gives diff when there's a stub and request found - with request body
stub_request("post", "https://hb.opencpu.org/post") %>%
wi_th(body = list(apple = "green"))
enable()
library(crul)
HttpClient$new("https://hb.opencpu.org")$post(
path = "post", body = list(apple = "red")
)
stub_body_diff()
# Gives diff when there's a stub and request found - with request body
stub_request("post", "https://hb.opencpu.org/post") %>%
wi_th(body = "the quick brown fox")
HttpClient$new("https://hb.opencpu.org")$post(
path = "post", body = "the quick black fox"
)
stub_body_diff()
}
Run the code above in your browser using DataLab