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().
req_get_body_type(req)
req_get_body(req, obfuscated = c("remove", "redact", "reveal"))A httr2 request object.
Form and JSON bodies can contain obfuscated values. This argument control what happens to them: should they be removed, redacted, or revealed.
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"