Getting Started with the SDK
This guide walks you through the most common tasks you’ll need to perform with our SDK.
1. Import the Library
import { Client } from '@mycompany/sdk';
2. Initialize the Client
const client = new Client({
apiKey: 'YOUR_API_KEY',
environment: 'production'
});
3. Make Your First Request
async function fetchData() {
try {
const result = await client.get('/data', { limit: 10 });
console.log(result);
} catch (err) {
console.error('Request failed:', err);
}
}
fetchData();
4. Handling Errors
All SDK errors inherit from SdkError
. You can inspect the code
property to react accordingly.
try {
await client.post('/submit', { data: {} });
} catch (err) {
if (err instanceof SdkError) {
switch (err.code) {
case 'auth/invalid-token':
// Refresh token logic
break;
case 'network/timeout':
// Retry logic
break;
}
}
}
5. Advanced: Streaming Responses
For large datasets you can stream results directly.
const stream = client.stream('/large-data');
for await (const chunk of stream) {
console.log('Received chunk:', chunk);
}
Next Steps
- Read the API reference for a full list of endpoints.
- Check out code examples for common patterns.
- Join our community forum for help.