Node.js SDK
The official Node.js SDK is under active development. In the meantime, use the REST API directly with fetch.
Using the REST API
Section titled “Using the REST API”const API_KEY = process.env.ASYNCQUEUE_API_KEY;const BASE_URL = 'https://api.asyncqueue.io';
async function createTask(taskData: Record<string, unknown>) { const response = await fetch(`${BASE_URL}/v1/tasks`, { method: 'POST', headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify(taskData) }); return response.json();}
async function getTask(taskId: string) { const response = await fetch(`${BASE_URL}/v1/tasks/${taskId}`, { headers: { 'Authorization': `Bearer ${API_KEY}` } }); return response.json();}
// Create a taskconst { task } = await createTask({ targetUrl: 'https://api.example.com/process', body: JSON.stringify({ orderId: 12345 }), maxRetries: 5});
console.log(`Task created: ${task.id}`);
// Check statusconst { task: result } = await getTask(task.id);console.log(`Status: ${result.status}`);SDK preview
Section titled “SDK preview”The SDK will provide a typed client with built-in error handling:
import { AsyncQueue } from '@asyncqueue/sdk';
const aq = new AsyncQueue({ apiKey: process.env.ASYNCQUEUE_API_KEY });
const task = await aq.tasks.create({ targetUrl: 'https://api.example.com/process', body: { orderId: 12345 }, maxRetries: 5, onCompleteUrl: 'https://api.example.com/done'});
const result = await aq.tasks.get(task.id);Want early access? Contact us.