This site counts visits with analytics cookies only if you accept. Read the consent

Skip to content

API ReferenceCallOptions

CallOptions

The options one call takes with .with(): its timeout, headers and signal, upload and download progress, a stream instead of parsed data, and the verb sent to the proxy.

3 min readUpdated both modes

Import

ts
import type { CallOptions, WithOptions } from "@noverax/courier/client"

Signature

A caller's .with(options) returns a caller whose every call carries them. It takes WithOptions, which is CallOptions without rawData: the status and headers of an answer come from the group's .raw accessor instead.

ts
type CallOptions = Omit<RequestInit, "method" | "body" | "signal"> & {
  signal?: AbortSignal | null
  timeout?: number
  stream?: boolean
  forwardVariables?: boolean
  method?: "GET" | "POST"
  responseType?: "json" | "text" | "blob" | "arrayBuffer" | "formData"
  onUploadProgress?: (progress: UploadProgress) => void
  onDownloadProgress?: (progress: DownloadProgress) => void
  coalesce?: boolean
  cancelPrevious?: boolean
  rawData?: boolean
}

type WithOptions = Omit<CallOptions, "rawData">

Properties

  • signal — aborts the call when it fires
  • timeout — milliseconds each request the call sends may take, from the moment it is sent, so each attempt of a retried call has its own; a call's own wins over the source's
  • headers — added to the call's headers, name by name, whatever their case; .with() at the client, a group and an endpoint merges them all
  • stream — answers with the response's body as a stream, unread, instead of the parsed data, where the fetch hands one over as it comes: React Native's own does not, and a call that asks for one there is refused with a ConfigurationError RESPONSE_STREAM_UNAVAILABLE
  • forwardVariables — whether the HTTP methods an endpoint calls send the call's variables by themselves, as the body of a write or the query of a read; false leaves them to the endpoint's own .via() code. Defaults to true
  • method — the verb the call goes to the proxy with: GET for a read that may be cached — one that declares .cache() and whose variables are not sensitive — and POST for every other call by default; "POST" keeps a read's variables out of the address
  • responseType — how a successful answer is read, when not as the source reads every answer
  • onUploadProgress — called as the body is sent, with percent from 0 to 1, transferredBytes and totalBytes; a callback that throws fails the call with what it threw, which no retry sends again, and so does one given to onDownloadProgress
  • onDownloadProgress — called as the answer comes in, in the same terms: as it is read, or as XMLHttpRequest takes it in for a call sent through it — one that does not read its answer as a stream: an upload that reports its progress, and in React Native a download that reports its own, unless the API sends its calls with a fetch of its own
  • coalesce — false sends the call alone, never joining an identical read already in flight; see Deduplication & Abort
  • cancelPrevious — whether this call cancels the older call of its read still in flight, and may be cancelled by a newer one, over what the endpoint, its groups, the client and the API say. .with() given to a whole client still decides call by call. A write is never cancelled, and a value other than true or false makes the call reject with ConfigurationError("CANCEL_PREVIOUS_INVALID"); see Deduplication & Abort
  • RequestInit — the rest of fetch's own options, cache, credentials, keepalive, mode, priority, redirect, referrer, referrerPolicy and integrity, passed to it as they are

Basic Usage

app/reports.ts
import { caller } from "@/lib/caller"

const controller = new AbortController()

// A slow endpoint gets more time, and the user can cancel it
const report = await caller.reports
  .with({ timeout: 30_000, signal: controller.signal })
  .generate({ type: "annual" })

// An upload reports how far it got, from 0 to 1
await caller.files
  .with({ onUploadProgress: ({ percent }) => console.log(`${Math.round(percent * 100)}%`) })
  .upload({ body: blob })
  • Request options — every option a source, a group and an endpoint take, and which wins
  • Types — TypedClient, GroupClient and the other types around a caller
  • Raw data — the .raw accessor for the status and headers