This pair of functions gives you sufficient information to capture the body of a request, and recreate, if needed. httr2 currently supports seven possible body types:
empty: no body.
raw: created by
req_body_raw()
with a raw vector.string: created by
req_body_raw()
with a string.file: created by
req_body_file()
.json: created by
req_body_json()
/req_body_json_modify()
.form: created by
req_body_form()
.multipart: created by
req_body_multipart()
.
Usage
req_get_body_type(req)
req_get_body(req, obfuscated = c("remove", "redact", "reveal"))
Arguments
- req
A httr2 request object.
- obfuscated
Form and JSON bodies can contain obfuscated values. This argument control what happens to them: should they be removed, redacted, or revealed.
Examples
req <- request(example_url())
req |> req_body_raw("abc") |> req_get_body_type()
#> [1] "string"
req |> req_body_file(system.file("DESCRIPTION")) |> req_get_body_type()
#> [1] "file"
req |> req_body_json(list(x = 1, y = 2)) |> req_get_body_type()
#> [1] "json"
req |> req_body_form(x = 1, y = 2) |> req_get_body_type()
#> [1] "form"
req |> req_body_multipart(x = "x", y = "y") |> req_get_body_type()
#> [1] "multipart"