Skip to main content
Confect’s HTTP integration mounts an Effect HTTP router onto Convex: you register routes with Effect’s effect/unstable/http and effect/unstable/httpapi modules—HttpApi endpoints, plain routes, interactive Scalar docs, middleware—and Confect serves them from a single Convex HTTP action, supplying its services to your handlers on every request.

Defining an API

Define API groups and endpoints using effect/unstable/httpapi, implement the endpoint handlers with HttpApiBuilder.group, and export a layer that registers the API’s routes. Handlers have access to the Confect services available in the HTTP action context. Endpoint paths are absolute; place an API under a path prefix with .prefix(...).
confect/http/NotesApi.ts
HttpApiBuilder.layer(Api) registers the API’s routes; Layer.provide(ApiLive) supplies its group handlers. Forgetting a group is a compile-time error—the unprovided group requirement is rejected where the layer is mounted.

API documentation

HttpApiScalar.layer serves interactive docs, powered by Scalar and generated from your endpoint definitions and OpenApi annotations. Set baseServerURL to your deployment’s site URL so the docs page’s “try it” requests target the right host—Confect installs a Convex-aware ConfigProvider, so Config reads (in layer construction, route handlers, and middleware alike) resolve against your Convex environment variables.
confect/http/ScalarDocs.ts

Creating the router

Create the Convex HTTP router in confect/http.ts with HttpRouter.make from @confect/server. It takes a single Layer that registers your routes—merge your API and docs layers with any other building blocks from Effect’s effect/unstable/http:
  • HttpRouter.add(method, path, handler) registers a plain route.
  • HttpRouter.middleware(fn, { global: true }) applies middleware to every route.
Confect’s HttpRouter module collides with Effect’s, so alias it on import:
confect/http.ts

Routing semantics

HttpRouter.make registers a single catch-all Convex HTTP action under the path prefix /, so the Effect router is the single source of truth for paths:
  • Any number of HttpApi definitions, docs pages, and plain routes can be merged onto the one router.
  • Requests that match no Effect route receive the Effect router’s 404 response.
  • Plain Convex routes still work: add them to the returned router with .route(...). Convex matches exact paths first and longer path prefixes before the catch-all, so they take precedence over the Effect router.
confect/http.ts (continued)