Use this file to discover all available pages before exploring further.
Confect allows you to expose your functions as HTTP endpoints using Effect’s HTTP API module. This enables you to call your backend from any HTTP client, with full OpenAPI documentation powered by Scalar.
First, define your HTTP API using Effect’s HTTP API module:
confect/http/path-prefix.ts
import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, OpenApi,} from "@effect/platform";import { Effect, Layer, Schema } from "effect";import refs from "../_generated/refs";import { QueryRunner } from "../_generated/services";import { Notes } from "../tables/Notes";// Define an API groupclass ApiGroup extends HttpApiGroup.make("notes") .add( HttpApiEndpoint.get("getFirst", "/get-first") .annotate(OpenApi.Description, "Get the first note, if there is one.") .addSuccess(Schema.Option(Notes.Doc)), ) .annotate(OpenApi.Title, "Notes") .annotate(OpenApi.Description, "Operations on notes.") {}// Define the APIexport class Api extends HttpApi.make("Api") .annotate(OpenApi.Title, "Confect Example") .annotate( OpenApi.Description, "An example API built with Confect." ) .add(ApiGroup) .prefix("/path-prefix") {}// Implement the API groupconst ApiGroupLive = HttpApiBuilder.group(Api, "notes", (handlers) => handlers.handle("getFirst", () => Effect.gen(function* () { const runQuery = yield* QueryRunner; const firstNote = yield* runQuery( refs.public.notesAndRandom.notes.getFirst, {}, ); return firstNote; }).pipe(Effect.orDie), ),);// Provide the implementationexport const ApiLive = HttpApiBuilder.api(Api).pipe( Layer.provide(ApiGroupLive),);
import { FetchHttpClient, HttpApiClient } from "@effect/platform";import { Effect } from "effect";import { Api } from "./confect/http/path-prefix";// Create the HTTP clientconst ApiClient = HttpApiClient.make(Api, { baseUrl: "https://your-deployment.convex.site",});// Call an endpointconst getFirst = ApiClient.pipe( Effect.andThen((client) => client.notes.getFirst()), Effect.scoped, Effect.provide(FetchHttpClient.layer),);// Run the effectconst result = await Effect.runPromise(getFirst);console.log(result);
class ApiGroup extends HttpApiGroup.make("notes") .add( HttpApiEndpoint.get("list", "/notes") .annotate(OpenApi.Title, "List all notes") .annotate( OpenApi.Description, `Returns all notes in the database, sorted by creation time.## UsageThis endpoint supports pagination via query parameters.## Rate Limits- 100 requests per minute- 1000 requests per hour ` ) .addSuccess(Schema.Array(Notes.Doc)) ) .annotate(OpenApi.Title, "Notes API") .annotate(OpenApi.Description, "Manage notes in your application") {}
HttpApiEndpoint.post("create", "/notes") .annotate(OpenApi.Title, "Create a note") .annotate(OpenApi.Description, "Creates a new note in the database") .setPayload(Schema.Struct({ text: Schema.String }))