Learn R Programming

whapi (version 0.0.2)

whapi_log_plumber_req: Log details of a Plumber request object using the cli package

Description

Prints 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$body or req$postBody).

Usage

whapi_log_plumber_req(
  req,
  show_headers = TRUE,
  show_cookies = TRUE,
  show_body = TRUE,
  max_chars = 2000L
)

Value

Invisibly returns NULL. The function is called for its side-effect of printing formatted logs to the console.

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.

show_cookies

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.

See Also

Examples

Run this code
if (FALSE) {
# 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)
}

Run the code above in your browser using DataLab