This section demonstrates how to configure and use the library to capture both automatic and manual tracking events.
const axios = require('axios');
const { config, interceptAxiosRequest, interceptFetchRequest, captureModel } = require('@handit.ai/node');
// Step 1: Configure the library with API key
config({
apiKey: 'your-api-key-here',
});
// Step 2: Set up Axios interceptor
const axiosInstance = axios.create();
interceptAxiosRequest(axiosInstance);
// Making a tracked Axios request
axiosInstance.post('/api/model', { input: 'inputData' })
.then(response => {
console.log(response.data); // Automatically tracked
});
// Step 3: Set up Fetch interceptor
interceptFetchRequest();
// Making a tracked Fetch request
fetch('/api/model', {
method: 'POST',
body: JSON.stringify({ input: 'inputData' }),
})
.then(response => response.json())
.then(data => {
console.log(data); // Automatically tracked
});
// Step 4: Manually capture model data
captureModel({
modelId: 'model-456',
requestBody: { input: 'manual input' },
responseBody: { output: 'manual output' }
});
This ensures that all relevant data is tracked, whether it's from automatic interceptors or manual input.