The APIs module provides standalone HTTP endpoints for data ingestion and analytics. Unlike other modules of the MooseStack, APIs are meant to be paired with other MooseStack modules like OLAP tables and streams.
If you'd prefer to use your own API framework of choice, instead of Moose APIs, see the Bring Your Own API Framework documentation for comprehensive examples and patterns using frameworks such as Express, Koa, Fastify, or FastAPI.
Ensure your API is correctly exported from your app/index.ts file.
Example: export { userEventsApi, userDataApi }
Learn more about export pattern: local development / hosted.
import { IngestApi } from "@514labs/moose-lib"; interface UserEvent { id: string; userId: string; timestamp: Date; eventType: string;} // Create a standalone ingestion APIexport const userEventsApi = new IngestApi<UserEvent>("user-events", { destination: eventStream});import { Api } from "@514labs/moose-lib"; interface Params { userId: string; limit: number;} interface ResultData { id: string; name: string; email: string;} // Create a standalone analytics APIexport const userDataApi = new Api<Params, ResultData[]>("user-data", async ({ userId, limit }, { client, sql }) => { // Query external service or custom logic return [ { id: userId, name: "John Doe", email: "john@example.com" } ]; });import { Api } from "@514labs/moose-lib"; interface Params { userId: string; limit: number;} interface ResultData { id: string; name: string; email: string;} // Create a standalone analytics APIexport const userDataApi = new Api<Params, ResultData[]>("user-data", async ({ userId, limit }, { client, sql }) => { // Query external service or custom logic return [ { id: userId, name: "John Doe", email: "john@example.com" } ]; });