Skip to main content

postStream

Sends a POST request and returns an async generator that yields parsed NDJSON objects as they arrive. Throws HomunculusApiError on non-OK responses, and HomunculusStreamError if an NDJSON line cannot be parsed.

Parameters

ParameterTypeDescription
urlURLThe URL to send the POST request to
bodyunknown (optional)Request body that will be JSON-serialized
signalAbortSignal (optional)Signal for cancellation

Returns

AsyncGenerator<T>

Example

import { host, type HomunculusStreamError } from "@hmcs/sdk";

const stream = host.postStream<{ type: string; data: string }>(
host.createUrl("commands/execute"),
{ command: "build" },
);

for await (const event of stream) {
console.log(event);
}