Insert a cassette to record HTTP requests
insert_cassette(name, record = "once", match_requests_on = c("method",
"uri"), update_content_length_header = FALSE,
allow_playback_repeats = FALSE, serialize_with = "yaml",
persist_with = "FileSystem", preserve_exact_body_bytes = FALSE,
ignore_cassettes = FALSE, re_record_interval = NULL,
clean_outdated_http_interactions = FALSE)
The name of the cassette. vcr will sanitize this to ensure it is a valid file name.
The record mode. Default: "once". In the future we'll support "once", "all", "none", "new_episodes". See recording for more information
List of request matchers
to use to determine what recorded HTTP interaction to replay. Defaults to
["method", "uri"]
. The built-in matchers are "method", "uri", "host",
"path", "headers" and "body"
(logical) Whether or
not to overwrite the Content-Length
header of the responses to
match the length of the response body. Default: FALSE
(logical) Whether or not to
allow a single HTTP interaction to be played back multiple times.
Default: FALSE
.
(character) Which serializer to use. Valid values are "yaml" (default), the only one supported for now.
(character) Which cassette persister to use. Default: "file_system". You can also register and use a custom persister.
(logical) Whether or not
to base64 encode the bytes of the requests and responses for
this cassette when serializing it. See also preserve_exact_body_bytes
in vcr_configure()
. Default: FALSE
(logical) turn vcr off and ignore cassette
insertions (so that no error is raised). Default: FALSE
(integer) How frequently (in seconds) the
cassette should be re-recorded. default: NULL
(not re-recorded)
(logical) Should outdated
interactions be recorded back to file? default: FALSE
an object of class Cassette
# NOT RUN {
library(vcr)
library(crul)
vcr_configure(dir = tempdir())
webmockr::webmockr_allow_net_connect()
(x <- insert_cassette(name = "leo5"))
current_cassette()
x$new_recorded_interactions
cli <- crul::HttpClient$new(url = "https://httpbin.org")
cli$get("get")
x$new_recorded_interactions
# very important when using inject_cassette: eject when done
x$eject() # same as eject_cassette("leo5")
# cleanup
unlink(file.path(tempdir(), "leo5.yml"))
# }
Run the code above in your browser using DataLab