Skip to contents

Configure custom response handler for an endpoint

Usage

payload_response_config(path, handler)

Arguments

path

The URL path to configure response handler for

handler

A function that accepts (payload, req) and returns a list with: status (HTTP status code), body (response body), content_type (MIME type), headers (additional headers). Pass NULL to remove the handler.

Value

Invisibly returns TRUE, called for side effects

Examples

if (interactive()) {
  # Set custom response handler
  payload_response_config("/api/process", function(payload, req) {
    list(
      status = 201L,
      body = list(
        received = TRUE,
        id = paste0("item_", sample(10000:99999, 1)),
        timestamp = Sys.time()
      )
    )
  })

  # Remove handler (use default response)
  payload_response_config("/api/process", NULL)
}