# first, make a stub object
req <- stub_request("post", "https://httpbin.org/post")
# add body
# list
wi_th(req, body = list(foo = "bar"))
# string
wi_th(req, body = '{"foo": "bar"}')
# raw
wi_th(req, body = charToRaw('{"foo": "bar"}'))
# numeric
wi_th(req, body = 5)
# an upload
wi_th(req, body = crul::upload(system.file("CITATION")))
# wi_th(req, body = httr::upload_file(system.file("CITATION")))
# add query - has to be a named list
wi_th(req, query = list(foo = "bar"))
# add headers - has to be a named list
wi_th(req, headers = list(foo = "bar"))
wi_th(req, headers = list(`User-Agent` = "webmockr/v1", hello = "world"))
# .list - pass in a named list instead
wi_th(req, .list = list(body = list(foo = "bar")))
# basic authentication
wi_th(req, basic_auth = c("user", "pass"))
wi_th(req, basic_auth = c("user", "pass"), headers = list(foo = "bar"))
# partial matching, query params
## including
wi_th(req, query = including(list(foo = "bar")))
## excluding
wi_th(req, query = excluding(list(foo = "bar")))
# partial matching, body
## including
wi_th(req, body = including(list(foo = "bar")))
## excluding
wi_th(req, body = excluding(list(foo = "bar")))
# basic auth
## including
wi_th(req, body = including(list(foo = "bar")))
## excluding
wi_th(req, body = excluding(list(foo = "bar")))
Run the code above in your browser using DataLab