LogoHuk Relay Docs

Read & Write Data

How to access and modify request data in functions

When a function is executed, it has access to the request object. This object represents the HTTP request being processed (either an incoming webhook or an intercepted forward).

Reading Request Data

You can access various properties of the request:

// Method
var method = request.method; // e.g., "POST"

// URL / Path
var path = request.path; // e.g., "/hooks/xxx"

// Headers
var contentType = request.headers['Content-Type'];

// Body (Raw string)
var body = request.body;

Modifying Request Data

You can modify these properties to transform the request before it is forwarded to its destination.

Modifying Body

// Set a new string body
request.body = "new body content";

// Or parsed JSON
var data = JSON.parse(request.body);
data.processed = true;
request.body = JSON.stringify(data);

Modifying Headers

// Add or update a header
request.headers['X-Custom-Header'] = 'modified-by-function';

// Remove a header
delete request.headers['Authorization'];