Skip to main content

Class: ConvexHttpClient

browser.ConvexHttpClient

A Convex client that runs queries and mutations over HTTP.

This is appropriate for server-side code (like Netlify Lambdas) or non-reactive webapps.

If you're building a React app, consider using ConvexReactClient instead.

Constructors

constructor

new ConvexHttpClient(address)

Create a new ConvexHttpClient.

Parameters

NameTypeDescription
addressstringThe url of your Convex deployment, often provided by an environment variable. E.g. https://small-mouse-123.convex.cloud.

Defined in

browser/http_client.ts:54

Methods

backendUrl

backendUrl(): string

Obtain the ConvexHttpClient's URL to its backend.

Returns

string

The URL to the Convex backend, including the client's API version.

Defined in

browser/http_client.ts:65


setAuth

setAuth(value): void

Set the authentication token to be used for subsequent queries and mutations.

Should be called whenever the token changes (i.e. due to expiration and refresh).

Parameters

NameTypeDescription
valuestringJWT-encoded OpenID Connect identity token.

Returns

void

Defined in

browser/http_client.ts:76


clearAuth

clearAuth(): void

Clear the current authentication token if set.

Returns

void

Defined in

browser/http_client.ts:92


query

query<Query>(query, ...args): Promise<FunctionReturnType<Query>>

Execute a Convex query function.

Type parameters

NameType
Queryextends FunctionReference<"query">

Parameters

NameTypeDescription
queryQuery-
...argsOptionalRestArgs<Query>The arguments object for the query. If this is omitted, the arguments will be {}.

Returns

Promise<FunctionReturnType<Query>>

A promise of the query's result.

Defined in

browser/http_client.ts:123


mutation

mutation<Mutation>(mutation, ...args): Promise<FunctionReturnType<Mutation>>

Execute a Convex mutation function.

Type parameters

NameType
Mutationextends FunctionReference<"mutation">

Parameters

NameTypeDescription
mutationMutation-
...argsOptionalRestArgs<Mutation>The arguments object for the mutation. If this is omitted, the arguments will be {}.

Returns

Promise<FunctionReturnType<Mutation>>

A promise of the mutation's result.

Defined in

browser/http_client.ts:185


action

action<Action>(action, ...args): Promise<FunctionReturnType<Action>>

Execute a Convex action function.

Type parameters

NameType
Actionextends FunctionReference<"action">

Parameters

NameTypeDescription
actionAction-
...argsOptionalRestArgs<Action>The arguments object for the action. If this is omitted, the arguments will be {}.

Returns

Promise<FunctionReturnType<Action>>

A promise of the action's result.

Defined in

browser/http_client.ts:246