CrulAdapter | R Documentation |
Adapter
is the base parent class used to implement
webmockr support for different HTTP clients. It should not be used
directly. Instead, use one of the client-specific adapters that webmockr
currently provides:
CrulAdapter
for crul
HttrAdapter
for httr
Note that the documented fields and methods are the same across all client-specific adapters.
webmockr::Adapter
-> CrulAdapter
client
HTTP client package name
name
adapter name
clone()
The objects of this class are cloneable with this method.
CrulAdapter$clone(deep = FALSE)
deep
Whether to make a deep clone.
webmockr::Adapter
-> HttrAdapter
client
HTTP client package name
name
adapter name
clone()
The objects of this class are cloneable with this method.
HttrAdapter$clone(deep = FALSE)
deep
Whether to make a deep clone.
client
HTTP client package name
name
adapter name
new()
Create a new Adapter object
Adapter$new()
enable()
Enable the adapter
Adapter$enable(quiet = FALSE)
quiet
(logical) suppress messages? default: FALSE
TRUE
, invisibly
disable()
Disable the adapter
Adapter$disable(quiet = FALSE)
quiet
(logical) suppress messages? default: FALSE
FALSE
, invisibly
handle_request()
All logic for handling a request
Adapter$handle_request(req)
req
a request
various outcomes
remove_stubs()
Remove all stubs
Adapter$remove_stubs()
nothing returned; removes all request stubs
clone()
The objects of this class are cloneable with this method.
Adapter$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run: if (requireNamespace("httr", quietly = TRUE)) { # library(httr) # normal httr request, works fine # real <- GET("https://httpbin.org/get") # real # with webmockr # library(webmockr) ## turn on httr mocking # httr_mock() ## now this request isn't allowed # GET("https://httpbin.org/get") ## stub the request # stub_request('get', uri = 'https://httpbin.org/get') %>% # wi_th( # headers = list('Accept' = 'application/json, text/xml, application/xml, */*') # ) %>% # to_return(status = 418, body = "I'm a teapot!", headers = list(a = 5)) ## now the request succeeds and returns a mocked response # (res <- GET("https://httpbin.org/get")) # res$status_code # rawToChar(res$content) # allow real requests while webmockr is loaded # webmockr_allow_net_connect() # webmockr_net_connect_allowed() # GET("https://httpbin.org/get?animal=chicken") # webmockr_disable_net_connect() # webmockr_net_connect_allowed() # GET("https://httpbin.org/get?animal=chicken") # httr_mock(FALSE) } ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.