Skip to content

send

hc.send(text, statusCode?, contentType?)

Available since v2.0.0

Signature:(text: string, statusCode?: number, contentType?: string) => Promise<void>

ParameterTypeDescription
textRequired. Response body text.
statusCodeOptional. HTTP status (default 200). Must be an integer between 100 and 599.
contentTypeOptional. Content-Type header value (default text/plain; charset=utf-8).

Treats the given text as the HTTP response for the current send — replacing status, headers, and body that would otherwise come from the remote server. Available in both pre-request and post-request scripts. Last call in the phase wins.

This is not hc.fetch (outbound helper HTTP from the sandbox). hc.send only supplies a synthetic response for the request being sent.

Use await — scripts are evaluated as async functions, so top-level await hc.send(...) is supported.

Does not skip the HTTP call by itself. In a pre-request script, also call hc.execution.skipRequest() when the remote request should not run. Without skipRequest, the real request still goes out; after the send (and after post-request scripts if they run), HarborClient discards the real response and shows the override instead.

Request history and plugin afterSend hooks still see the real response when a send occurred.

Throws when statusCode is not an integer between 100 and 599.

javascript
await hc.send("Service unavailable", 503, "text/plain; charset=utf-8");
hc.execution.skipRequest();