Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
@algolia/transporter
Advanced tools
Promise-based transporter layer with embedded retry strategy.
@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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.