Skip to main content

Overview

ConvexHttpClient is a stateful client that runs queries and mutations over HTTP instead of WebSocket. This is appropriate for server-side code (like serverless functions, API routes, or backend services) or non-reactive web applications.
This client is stateful (it has user credentials and queues mutations), so take care to avoid sharing it between requests in a server. Create a new instance per request when using in server-side code.

Constructor

Create a new ConvexHttpClient instance.

Parameters

string
required
The URL of your Convex deployment, often provided by an environment variable. For example: https://small-mouse-123.convex.cloud
object
Optional configuration object for the client.

Methods

query

Execute a Convex query function.
FunctionReference<'query'>
required
A function reference for the public query to run, like api.dir1.dir2.filename.func.
object
An arguments object for the query. If omitted, the arguments will be {}.
Returns: A promise of the query’s result.

mutation

Execute a Convex mutation function. Mutations are queued by default.
FunctionReference<'mutation'>
required
A function reference for the public mutation to run.
object
An arguments object for the mutation. If omitted, the arguments will be {}.
HttpMutationOptions
Returns: A promise of the mutation’s result.
By default, mutations are queued and executed sequentially. This ensures mutations are applied in order. Set skipQueue: true to execute mutations in parallel.

action

Execute a Convex action function. Actions are not queued.
FunctionReference<'action'>
required
A function reference for the public action to run.
object
An arguments object for the action. If omitted, the arguments will be {}.
Returns: A promise of the action’s result.

setAuth

Set the authentication token to be used for subsequent queries and mutations.
string
required
JWT-encoded OpenID Connect identity token.
Should be called whenever the token changes (e.g., due to expiration and refresh).

clearAuth

Clear the current authentication token if set.

Properties

url

Return the address for this client.
Returns: The Convex deployment URL as a string.
Not guaranteed to match the address used in the constructor as it may be canonicalized.

Example usage

Basic usage in a serverless function

With authentication

Parallel mutations with skipQueue

Next.js API route

Comparison with ConvexReactClient

Use ConvexHttpClient for server-side code and ConvexReactClient for React applications. If you need to use Convex in a non-React frontend, consider using ConvexHttpClient with polling or use the WebSocket-based BaseConvexClient (advanced usage).