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 usingeffect/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 inconfect/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.
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
HttpApidefinitions, 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)