MooseStack

Moose APIs

Moose APIs

Viewing:

Overview

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.

Core Capabilities

Ingest

Ingest New Data

Create HTTP POST endpoints for data ingestion with validation and routing
Analytics

Expose Analytics

Create HTTP GET endpoints for reading data from your OLAP database with query parameters
Trigger

Trigger Workflows

Create HTTP POST endpoints to trigger workflows and other processes

Basic Examples

Export Required

Ensure your API is correctly exported from your app/index.ts file.

Learn more about export pattern: local development / hosted.

Ingestion API

IngestApi.ts
import { IngestApi } from "@514labs/moose-lib";
 
interface UserEvent {
  id: string;
  userId: string;
  timestamp: Date;
  eventType: string;
}
 
// Create a standalone ingestion API
export const userEventsApi = new IngestApi<UserEvent>("user-events", {
  destination: eventStream
});

Analytics API

AnalyticsApi.ts
import { Api } from "@514labs/moose-lib";
 
interface Params {
  userId: string;
  limit: number;
}
 
interface ResultData {
  id: string;
  name: string;
  email: string;
}
 
// Create a standalone analytics API
export 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" }
    ];
  }
);