api-client
Effect services for the Aperture REST API.
npm install @aperture-browser/api-client effectEach API area is a service: AuthApi, SessionsApi, SnapshotsApi, TenantsApi, UsersApi, TokensApi and EventsApi. apiClientLayer provides all of them over the HttpClient your app supplies, and baseUrlLayer points it at an instance on another origin. Failures are ApiRequestErrors carrying the server's error code and HTTP status.
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
import { apiClientLayer, baseUrlLayer, SessionsApi } from "@aperture-browser/api-client";
const credentials = {
kind: "bearer",
token: process.env.APERTURE_TOKEN!,
authorityType: "tenant",
tenantId: "my-tenant",
selectedTenantId: null,
} as const;
const program = SessionsApi.use((sessions) => sessions.listSessions(credentials, { limit: 20 }));
const layer = apiClientLayer.pipe(
Layer.provide(baseUrlLayer("https://aperture.example.com")),
Layer.provide(FetchHttpClient.layer),
);
const page = await Effect.runPromise(program.pipe(Effect.provide(layer)));The endpoints, their parameters and error codes are in the REST API reference.
api-schema
@aperture-browser/api-schema holds the Effect Schemas and a typed HttpClient generated from the OpenAPI spec with @effect/openapi-generator. api-client builds on it; depend on it directly only when you need the raw generated client.
Both require effect 4.