Docs

API Reference

Complete API reference for Alien Worker bindings.

The Worker binding enables direct worker-to-worker invocation — low-latency internal calls that bypass public endpoints.

invoke

Invokes a worker with a full HTTP request.

const response = await func.invoke(request)
// response: { status: number, headers: Record<string, string>, body: Uint8Array }
let response = func.invoke(WorkerInvokeRequest {
    target_worker: "processor".into(),
    method: "POST".into(),
    path: "/resize".into(),
    headers: BTreeMap::new(),
    body: payload_bytes,
    timeout: Some(Duration::from_secs(30)),
}).await?;
ParameterTypeRequiredDescription
request.targetWorkerstringYesWorker name or identifier.
request.methodstringYesHTTP method (GET, POST, PUT, DELETE, etc.).
request.pathstringYesRequest path (e.g., /resize).
request.headersRecord<string, string>NoHTTP headers.
request.bodyUint8ArrayNoRequest body as bytes.
request.timeoutMsnumberNoTimeout in milliseconds.

Returns: WorkerInvokeResponse{ status: number, headers: Record<string, string>, body: Uint8Array }


invokeJson

High-level JSON invocation with typed request and response.

const result = await func.invokeJson<TReq, TRes>(
  targetWorker: string,
  body: TReq,
  options?: {
    method?: string       // default: "POST"
    path?: string         // default: "/"
    headers?: Record<string, string>
    timeoutMs?: number
  }
): Promise<TRes>

Automatically serializes the request body as JSON and parses the response body as JSON.


get

Convenience method for GET requests with a typed JSON response.

const result = await func.get<TRes>(
  targetWorker: string,
  path?: string,
  options?: {
    headers?: Record<string, string>
    timeoutMs?: number
  }
): Promise<TRes>

getUrl

Returns the worker's public URL, if it has public ingress configured.

const url = await func.getUrl(): Promise<string | undefined>
async fn get_worker_url(&self) -> Result<Option<String>>

Returns undefined / None if the worker has private ingress only.


Types

WorkerInvokeRequest

interface WorkerInvokeRequest {
  targetWorker: string
  method: string
  path: string
  headers?: Record<string, string>
  body?: Uint8Array
  timeoutMs?: number
}
pub struct WorkerInvokeRequest {
    pub target_worker: String,
    pub method: String,
    pub path: String,
    pub headers: BTreeMap<String, String>,
    pub body: Vec<u8>,
    pub timeout: Option<Duration>,
}

WorkerInvokeResponse

interface WorkerInvokeResponse {
  status: number
  headers: Record<string, string>
  body: Uint8Array
}
pub struct WorkerInvokeResponse {
    pub status: u16,
    pub headers: BTreeMap<String, String>,
    pub body: Vec<u8>,
}

On this page