Documentation

ApexKit offers a dual-interface: a fully typed TypeScript SDK for rapid development, and a standard REST API for universal compatibility.

Initialization & Context

Initialize Client

Configure the SDK. ApexKit supports multi-tenancy natively. You can switch contexts (Root, Tenant, Sandbox) using the same client library.
import { ApexKit } from 'apexkit-sdk';

// 1. Root Connection (Platform Admin)
const client = new ApexKit('https://api.apexkit.io');

// 2. Tenant Context (Customer Data)
const tenantClient = client.tenant('customer-123');

// 3. Sandbox Context (AI Architect)
const sandboxClient = client.sandbox('session-uuid');

Authentication

POST

Login

/auth/login
Authenticate a user to receive a JWT. The token scope adapts automatically to the client context (Root/Tenant).
const { token, user } = await client.auth.login(
  'alice@example.com', 
  'password123'
);

// SDK automatically attaches token to future requests
console.log(user.role); // "admin" | "user"
POST

Register

/auth/register
Create a new user. Metadata is a flexible JSON object for profile fields.
await client.auth.register(
  'bob@example.com', 
  'securePass!', 
  'user', // Role
  { full_name: "Bob", plan: "free" } // Metadata
);

Database (CRUD)

GET

List Records

/collections/{id}/records
Fetch paginated data. Supports JSON filtering and Relation expansion.
const result = await client.collection('posts').list({
  page: 1,
  per_page: 20,
  sort: '-created',
  filter: { 
    status: 'published',
    views: { $gt: 100 }
  },
  expand: 'author_id'
});

console.log(result.items);
POST

Create Record

/collections/{id}/records
Insert a new record. Schema validation runs automatically on the server.
const post = await client.collection('posts').create({
  title: "Hello World",
  content: "My first post...",
  author_id: client.auth.user.id
});
POST

Manage Relations

/.../relations
Manually link two records (Graph Edge). Useful for Many-to-Many relationships.
await client.collection('posts').addRelation(
  'post_123', // Origin Record
  'tags',     // Target Collection
  'tag_55',   // Target Record
  'tagged_as' // Relation Name
);

File Storage

POST

Upload File

/storage/upload
Uploads to configured backend (Local Disk or S3). Returns a File Object with public URL.
const file = document.getElementById('fileInput').files[0];
const uploaded = await client.files.upload(file);

console.log(uploaded.url); // Public URL
console.log(uploaded.filename); // Store this in DB

Serverless Logic

POST

Run Script

/run/{name}
Execute a server-side JavaScript function. Ideal for payment processing, heavy calculations, or secure webhooks.
const response = await client.scripts.run(
  'process-payment', 
  { 
    amount: 5000, 
    currency: 'USD' 
  }
);
POST

Run AI Action

/ai/run/{slug}
Execute a stored Prompt Template securely on the server. The server handles API keys and context.
const res = await client.ai.run('summarize', {
    text: "Long article content..."
});

console.log(res.result); // AI Generated Text

Realtime (WS)

WS

Subscribe to Events

/ws
Listen for database changes (Insert, Update, Delete) or custom broadcast signals.
const rt = new ApexKitRealtimeWSClient(url, token);
rt.connect();

// 1. DB Changes
rt.subscribe({
    collectionId: 5,
    eventType: 'Insert'
});

// 2. Custom Signals (Chat)
rt.subscribe({ channel: 'room_1' });

rt.onEvent((msg) => console.log(msg));