SDK Documentation
Official client libraries: JavaScript, TypeScript, Python, Go, Ruby, Java, C#, PHP, Swift, and Dart/Flutter
Installation
npm install mudbase-sdknpm install mudbase-sdkQuick Start
Every SDK follows the same shape: a Configuration holding your base URL and API key, plus one class per API resource (AuthenticationApi, CollectionsApi, DataApi, and so on). There is no separate unified client wrapper — construct the resource classes you need directly.
import { Configuration, AuthenticationApi, DataApi } from 'mudbase-sdk';
const configuration = new Configuration({
basePath: 'https://cloud.mudbase.dev',
apiKey: process.env.MUDBASE_API_KEY,
});
const auth = new AuthenticationApi(configuration);
const data = new DataApi(configuration);
// Log in an end-user of your project
const { data: session } = await auth.loginUser({
email: 'morgan.chen@northwind.dev',
password: 'hunter2',
});
// List documents in a collection
const { data: items } = await data.listData(projectId, collectionId);
// Create a document
const { data: created } = await data.createData(projectId, collectionId, {
name: 'Morgan Chen',
});import { Configuration, AuthenticationApi, DataApi } from 'mudbase-sdk';
const configuration = new Configuration({
basePath: 'https://cloud.mudbase.dev',
apiKey: process.env.MUDBASE_API_KEY,
});
const auth = new AuthenticationApi(configuration);
const data = new DataApi(configuration);
// Log in an end-user of your project
const { data: session } = await auth.loginUser({
email: 'morgan.chen@northwind.dev',
password: 'hunter2',
});
// List documents in a collection
const { data: items } = await data.listData(projectId, collectionId);
// Create a document
const { data: created } = await data.createData(projectId, collectionId, {
name: 'Morgan Chen',
});Error Handling
Every SDK surfaces failed requests as a language-native exception carrying the HTTP status code and response body — check the status code to distinguish validation errors (422), auth failures (401/403), and not-found (404).
import { isAxiosError } from 'axios';
try {
await data.createData(projectId, collectionId, { name: 'Morgan Chen' });
} catch (error) {
if (isAxiosError(error) && error.response) {
console.error(`Request failed (${error.response.status}):`, error.response.data);
} else {
console.error('Unexpected error:', error);
}
}import { isAxiosError } from 'axios';
try {
await data.createData(projectId, collectionId, { name: 'Morgan Chen' });
} catch (error) {
if (isAxiosError(error) && error.response) {
console.error(`Request failed (${error.response.status}):`, error.response.data);
} else {
console.error('Unexpected error:', error);
}
}Pagination
List endpoints accept page and limit query parameters. There is no built-in auto-pagination iterator — loop until a page returns fewer than limit results.
// listData accepts page/limit query params — check the API reference for
// each endpoint's exact parameter names.
const { data: page1 } = await data.listData(projectId, collectionId, 1, 20);
const { data: page2 } = await data.listData(projectId, collectionId, 2, 20);// listData accepts page/limit query params — check the API reference for
// each endpoint's exact parameter names.
const { data: page1 } = await data.listData(projectId, collectionId, 1, 20);
const { data: page2 } = await data.listData(projectId, collectionId, 2, 20);Advanced Configuration
Point the client at a different environment or attach custom headers:
// Point at a different environment and pass extra headers via baseOptions
const configuration = new Configuration({
basePath: 'https://api-staging.mudbase.dev',
apiKey: process.env.MUDBASE_API_KEY,
baseOptions: {
headers: { 'X-Custom-Header': 'value' },
},
});// Point at a different environment and pass extra headers via baseOptions
const configuration = new Configuration({
basePath: 'https://api-staging.mudbase.dev',
apiKey: process.env.MUDBASE_API_KEY,
baseOptions: {
headers: { 'X-Custom-Header': 'value' },
},
});Real-time Features
Mudbase's realtime layer (data change events, presence, chat) runs over WebSockets and is a separate protocol from the REST API these SDKs wrap — it isn't exposed as a method on any of the classes above. See the Realtime Events guide for connecting directly and authenticating a WebSocket session.