Skip to main content

Class: ConvexHttpClient<API>

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.

Type parameters

NameType
APIextends GenericAPI

Constructors

constructor

new ConvexHttpClient<API>(address)

Type parameters

NameType
APIextends GenericAPI

Parameters

NameType
addressstring

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.


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


clearAuth

clearAuth(): void

Clear the current authentication token if set.

Returns

void


query

query<Name>(name): (...args: Parameters<NamedQuery<API, Name>>) => Promise<ReturnType<NamedQuery<API, Name>>>

Construct a new Query.

Type parameters

NameType
Nameextends string

Parameters

NameTypeDescription
nameNameThe name of the query function.

Returns

fn

The Query object with that name.

▸ (...args): Promise<ReturnType<NamedQuery<API, Name>>>

Parameters
NameType
...argsParameters<NamedQuery<API, Name>>
Returns

Promise<ReturnType<NamedQuery<API, Name>>>


mutation

mutation<Name>(name): (...args: Parameters<NamedMutation<API, Name>>) => Promise<ReturnType<NamedMutation<API, Name>>>

Construct a new Mutation.

Type parameters

NameType
Nameextends string

Parameters

NameTypeDescription
nameNameThe name of the mutation function.

Returns

fn

The Mutation object with that name.

▸ (...args): Promise<ReturnType<NamedMutation<API, Name>>>

Parameters
NameType
...argsParameters<NamedMutation<API, Name>>
Returns

Promise<ReturnType<NamedMutation<API, Name>>>


action

action<Name>(name): (...args: Parameters<NamedAction<API, Name>>) => Promise<ReturnType<NamedAction<API, Name>>>

Construct a new Action.

Type parameters

NameType
Nameextends string

Parameters

NameTypeDescription
nameNameThe name of the action.

Returns

fn

The Action object with that name.

▸ (...args): Promise<ReturnType<NamedAction<API, Name>>>

Parameters
NameType
...argsParameters<NamedAction<API, Name>>
Returns

Promise<ReturnType<NamedAction<API, Name>>>