Skip to main content
HttpClient is an Effect service that wraps Convex’s ConvexHttpClient. It provides query, mutation, and action methods that accept refs and automatically encode args and decode return values through the schemas defined in your function specs. It works in any JavaScript runtime that supports fetch.

Setup

Create the HttpClient layer by passing your Convex deployment URL.
The layer can then be provided to any Effect that uses the HttpClient service.

Calling functions

Use the HttpClient service inside Effect.gen to call your functions with refs, the same way you would with @confect/react hooks or @confect/test.
Each method returns an Effect that can fail with HttpClientError (wrapping transport-level errors) or ParseResult.ParseError (if schema encoding or decoding fails).

Typed errors

When a ref’s spec declares an error schema, the decoded error is added to the returned Effect’s error channel alongside HttpClientError and ParseError. See Error Handling for how to declare error schemas.
Recover from a typed failure with Effect.catchTag (or any other Effect error combinator).

Authentication

Set or clear the auth token before making authenticated requests.

Running programs

Provide the HttpClient layer when running your program.

Differences from ConvexHttpClient