Light Logo
JavaScript SDK (v0.34.0)Reference

API

Client for WriftAI's API.

Class: API

Client for WriftAI's API.

Constructors

Constructor

new API(baseUrl, fetchImpl, accessToken?, headers?): API

Create an instance of the API client.

Parameters

baseUrl

string

Base URL for the API without trailing slashes.

fetchImpl

{(input, init?): Promise<Response>; (input, init?): Promise<Response>; }

Fetch implementation to use.

accessToken?

string

Optional bearer token used for authentication

headers?

Record<string, string>

Optional additional headers (overrides defaults).

Returns

API

Methods

request()

request<T>(path, options): Promise<T>

Makes an HTTP request to the API.

Type Parameters

T

T

The expected JSON response shape

Parameters

path

string

The path relative to baseUrl (e.g. /users)

options

Request options

body?

JsonValue

Optional JSON-serializable body

headers?

Record<string, string>

Optional extra request headers

method

"GET" | "POST" | "PUT" | "PATCH" | "DELETE"

The HTTP method to use

params?

Record<string, string | number | boolean | string[]>

Optional query parameters

signal?

AbortSignal

Optional AbortSignal to cancel the request.

Returns

Promise<T>

The parsed JSON response

Throws

If the response is not ok (!res.ok)

Example

const users = await client.request<User[]>("/users", { method: "GET" });