library(httr2)
without_internet({
expect_GET(
request("http://httpbin.org/get") %>% req_perform(),
"http://httpbin.org/get"
)
expect_GET(
request("http://httpbin.org/get") %>% req_perform(),
"http://httpbin.org/[a-z]+",
fixed = FALSE # For regular expression matching
)
expect_PUT(
request("http://httpbin.org/put") %>%
req_method("PUT") %>%
req_body_json(list(a = 1)) %>%
req_perform(),
"http://httpbin.org/put",
'{"a":1}'
)
# Don't need to assert the request body, or even the URL
expect_PUT(
request("http://httpbin.org/put") %>%
req_method("PUT") %>%
req_body_json(list(a = 1)) %>%
req_perform()
)
expect_no_request(rnorm(5))
})
Run the code above in your browser using DataLab