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.
To ConvexHttpClient with TypeScript type specific to your API, pass
in the API
type parameter:
import { ConvexHttpClient } from "convex/browser";
import { API } from "./convex/_generated/api";
const client = new ConvexHttpClient<API>(process.env["CONVEX_URL"]);
Type parameters
Name | Type |
---|---|
API | extends GenericAPI |
Constructors
constructor
• new ConvexHttpClient<API
>(address
)
Create a new ConvexHttpClient.
Type parameters
Name | Type |
---|---|
API | extends GenericAPI |
Parameters
Name | Type | Description |
---|---|---|
address | string | The url of your Convex deployment, often provided by an environment variable. E.g. https://small-mouse-123.convex.cloud . |
Defined in
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
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
Name | Type | Description |
---|---|---|
value | string | JWT-encoded OpenID Connect identity token. |
Returns
void
Defined in
clearAuth
▸ clearAuth(): void
Clear the current authentication token if set.
Returns
void
Defined in
query
▸ query<Name
>(name
, ...args
): Promise
<ReturnType
<NamedQuery
<API
, Name
>>>
Execute a Convex query function.
Type parameters
Name | Type |
---|---|
Name | extends string |
Parameters
Name | Type | Description |
---|---|---|
name | Name | The name of the query. |
...args | OptionalRestArgs <NamedQuery <API , Name >> | The arguments object for the query. If this is omitted, the arguments will be {} . |
Returns
Promise
<ReturnType
<NamedQuery
<API
, Name
>>>
A promise of the query's result.
Defined in
mutation
▸ mutation<Name
>(name
, ...args
): Promise
<ReturnType
<NamedMutation
<API
, Name
>>>
Execute a Convex mutation function.
Type parameters
Name | Type |
---|---|
Name | extends string |
Parameters
Name | Type | Description |
---|---|---|
name | Name | The name of the mutation. |
...args | OptionalRestArgs <NamedMutation <API , Name >> | The arguments object for the mutation. If this is omitted, the arguments will be {} . |
Returns
Promise
<ReturnType
<NamedMutation
<API
, Name
>>>
A promise of the mutation's result.
Defined in
action
▸ action<Name
>(name
, ...args
): Promise
<ReturnType
<NamedAction
<API
, Name
>>>
Execute a Convex action function.
Type parameters
Name | Type |
---|---|
Name | extends string |
Parameters
Name | Type | Description |
---|---|---|
name | Name | The name of the action. |
...args | OptionalRestArgs <NamedAction <API , Name >> | The arguments object for the action. If this is omitted, the arguments will be {} . |
Returns
Promise
<ReturnType
<NamedAction
<API
, Name
>>>
A promise of the action's result.