SDK Documentation

Official client libraries: JavaScript, TypeScript, Python, Go, Ruby, Java, C#, PHP, and Swift

Installation

npm install mudbase-sdk
npm install mudbase-sdk

Quick Start

Initialize the client with your API key and start making requests:

import { MudbaseClient } from 'mudbase-sdk';

const client = new MudbaseClient({
  apiKey: process.env.MUDBASE_API_KEY
});

// List users
const users = await client.users.list();

// Create a user
const newUser = await client.users.create({
  email: 'morgan.chen@northwind.dev',
  name: 'Morgan Chen'
});

// Get user by ID
const user = await client.users.get(userId);

// Update user
await client.users.update(userId, {
  name: 'Avery Park'
});

// Delete user
await client.users.delete(userId);
import { MudbaseClient } from 'mudbase-sdk';

const client = new MudbaseClient({
  apiKey: process.env.MUDBASE_API_KEY
});

// List users
const users = await client.users.list();

// Create a user
const newUser = await client.users.create({
  email: 'morgan.chen@northwind.dev',
  name: 'Morgan Chen'
});

// Get user by ID
const user = await client.users.get(userId);

// Update user
await client.users.update(userId, {
  name: 'Avery Park'
});

// Delete user
await client.users.delete(userId);

Error Handling

All SDKs provide consistent error handling:

try {
  const user = await client.users.create({
    email: 'invalid-email'
  });
} catch (error) {
  if (error.code === 'VALIDATION_ERROR') {
    console.error('Validation failed:', error.details);
  } else if (error.code === 'UNAUTHORIZED') {
    console.error('Invalid API key');
  } else {
    console.error('Unexpected error:', error.message);
  }
}
try {
  const user = await client.users.create({
    email: 'invalid-email'
  });
} catch (error) {
  if (error.code === 'VALIDATION_ERROR') {
    console.error('Validation failed:', error.details);
  } else if (error.code === 'UNAUTHORIZED') {
    console.error('Invalid API key');
  } else {
    console.error('Unexpected error:', error.message);
  }
}

Pagination

Iterate through paginated results:

// Manual pagination
const page1 = await client.users.list({ page: 1, per_page: 20 });
const page2 = await client.users.list({ page: 2, per_page: 20 });

// Auto-pagination helper
for await (const user of client.users.listAll()) {
  console.log(user.email);
}
// Manual pagination
const page1 = await client.users.list({ page: 1, per_page: 20 });
const page2 = await client.users.list({ page: 2, per_page: 20 });

// Auto-pagination helper
for await (const user of client.users.listAll()) {
  console.log(user.email);
}

Advanced Configuration

const client = new MudbaseClient({
  apiKey: process.env.MUDBASE_API_KEY,
  
  // Custom base URL (for testing)
  baseUrl: 'https://api-staging.mudbase.dev',
  
  // Request timeout (ms)
  timeout: 30000,
  
  // Retry configuration
  retry: {
    maxRetries: 3,
    retryDelay: 1000,
  },
  
  // Custom headers
  headers: {
    'X-Custom-Header': 'value'
  },
  
  // Logging
  logger: console,
});
const client = new MudbaseClient({
  apiKey: process.env.MUDBASE_API_KEY,
  
  // Custom base URL (for testing)
  baseUrl: 'https://api-staging.mudbase.dev',
  
  // Request timeout (ms)
  timeout: 30000,
  
  // Retry configuration
  retry: {
    maxRetries: 3,
    retryDelay: 1000,
  },
  
  // Custom headers
  headers: {
    'X-Custom-Header': 'value'
  },
  
  // Logging
  logger: console,
});

Real-time Features

Subscribe to real-time updates using WebSocket connections:

// Subscribe to project analytics
const subscription = client.realtime.subscribe('project-analytics', {
  projectId: 'proj_123'
});

subscription.on('data', (analytics) => {
  console.log('Active users:', analytics.active_users);
  console.log('Page views:', analytics.page_views);
});

subscription.on('error', (error) => {
  console.error('Connection error:', error);
});

// Unsubscribe
subscription.close();
// Subscribe to project analytics
const subscription = client.realtime.subscribe('project-analytics', {
  projectId: 'proj_123'
});

subscription.on('data', (analytics) => {
  console.log('Active users:', analytics.active_users);
  console.log('Page views:', analytics.page_views);
});

subscription.on('error', (error) => {
  console.error('Connection error:', error);
});

// Unsubscribe
subscription.close();

Additional Resources