
Log details of a Plumber request object using the cli package
Source:R/webhook.R
whapi_log_plumber_req.RdPrints a structured summary of a req object (Plumber request) to the console,
with colored and formatted output using the cli package.
This helper is useful for debugging APIs, inspecting request metadata,
and logging incoming payloads in a readable way.
The function logs:
HTTP method, path, query string, host, client IP/port, content type, and length.
Parsed arguments:
argsQuery,argsBody,args.Headers (with sensitive values redacted).
Cookies (always redacted).
Parsed request body (
req$bodyorreq$postBody).
Usage
whapi_log_plumber_req(
req,
show_headers = TRUE,
show_cookies = TRUE,
show_body = TRUE,
max_chars = 2000L
)Arguments
- req
A Plumber request object, usually passed automatically inside an endpoint. Must contain fields such as
REQUEST_METHOD,PATH_INFO,HTTP_HOST, etc.- show_headers
Logical. Whether to print request headers (default:
TRUE). Sensitive values are redacted.Logical. Whether to print cookies (default:
TRUE). Values are always redacted.- show_body
Logical. Whether to print the parsed body or raw
postBody(default:TRUE). Useful for debugging JSON payloads.- max_chars
Integer. Maximum number of characters to print for large JSON or raw bodies. Defaults to
2000.
Value
Invisibly returns NULL. The function is called for its side-effect
of printing formatted logs to the console.
Examples
if (FALSE) { # \dontrun{
# Inside a Plumber endpoint
#* @post /myendpoint
function(req, res) {
whapi_log_plumber_req(req) # Prints nicely formatted info about the incoming request
list(success = TRUE)
}
# Print only metadata, no headers/body
whapi_log_plumber_req(req, show_headers = FALSE, show_body = FALSE)
} # }