Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@algolia/transporter
Advanced tools
@algolia/transporter is a low-level HTTP client for making requests to Algolia's API. It provides a set of utilities to handle retries, timeouts, and other network-related concerns, making it easier to interact with Algolia's services.
Basic Request
This code demonstrates how to create a basic transporter instance and make a GET request to list all indexes in an Algolia application.
const { createTransporter } = require('@algolia/transporter');
const transporter = createTransporter({
hosts: [{ url: 'https://your-algolia-instance.algolia.net' }],
headers: { 'X-Algolia-API-Key': 'your-api-key', 'X-Algolia-Application-Id': 'your-app-id' }
});
transporter.read({ method: 'GET', path: '/1/indexes' }).then(response => {
console.log(response);
});
Handling Retries
This code shows how to configure the transporter to handle retries with specific timeout settings and retry policies.
const { createTransporter } = require('@algolia/transporter');
const transporter = createTransporter({
hosts: [{ url: 'https://your-algolia-instance.algolia.net' }],
headers: { 'X-Algolia-API-Key': 'your-api-key', 'X-Algolia-Application-Id': 'your-app-id' },
timeouts: { connect: 1, read: 2, write: 30 },
retry: { maxRetries: 3, delay: 1000 }
});
transporter.read({ method: 'GET', path: '/1/indexes' }).then(response => {
console.log(response);
});
Custom Headers
This example demonstrates how to add custom headers to the transporter instance for making requests.
const { createTransporter } = require('@algolia/transporter');
const transporter = createTransporter({
hosts: [{ url: 'https://your-algolia-instance.algolia.net' }],
headers: { 'X-Algolia-API-Key': 'your-api-key', 'X-Algolia-Application-Id': 'your-app-id', 'Custom-Header': 'custom-value' }
});
transporter.read({ method: 'GET', path: '/1/indexes' }).then(response => {
console.log(response);
});
Axios is a promise-based HTTP client for the browser and Node.js. It provides a simple API for making HTTP requests and handling responses, including support for interceptors, automatic JSON transformation, and more. Compared to @algolia/transporter, Axios is more general-purpose and not specifically tailored for Algolia's API.
Node-fetch is a lightweight module that brings `window.fetch` to Node.js. It allows you to make HTTP requests in a similar way to the Fetch API in the browser. While it is more low-level compared to @algolia/transporter, it can be used to interact with any HTTP API, including Algolia's.
Request-promise-native is a simplified HTTP request client for Node.js with Promise support. It is built on top of the `request` library and provides a more modern API for making HTTP requests. Like Axios, it is more general-purpose and not specifically designed for Algolia's API.
FAQs
Promise-based transporter layer with embedded retry strategy.
We found that @algolia/transporter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.