Socket
Socket
Sign inDemoInstall

@algolia/requester-node-http

Package Overview
Dependencies
1
Maintainers
3
Versions
191
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/requester-node-http


Version published
Weekly downloads
1.4M
decreased by-0.77%
Maintainers
3
Created
Weekly downloads
 

Package description

What is @algolia/requester-node-http?

@algolia/requester-node-http is a Node.js HTTP requester designed to be used with Algolia's API clients. It provides a simple and efficient way to make HTTP requests, particularly suited for interacting with Algolia's services.

What are @algolia/requester-node-http's main functionalities?

Basic HTTP Request

This feature allows you to make a basic HTTP GET request using the @algolia/requester-node-http package. The code sample demonstrates how to create a requester and send a GET request to a specified URL.

const { createNodeHttpRequester } = require('@algolia/requester-node-http');

const requester = createNodeHttpRequester();

const request = {
  method: 'GET',
  url: 'https://example.com',
  headers: {},
  data: null,
  responseType: 'json'
};

requester.send(request).then(response => {
  console.log(response);
}).catch(error => {
  console.error(error);
});

POST Request with Data

This feature allows you to make a POST request with a JSON payload. The code sample demonstrates how to create a requester and send a POST request with data to a specified URL.

const { createNodeHttpRequester } = require('@algolia/requester-node-http');

const requester = createNodeHttpRequester();

const request = {
  method: 'POST',
  url: 'https://example.com/api',
  headers: { 'Content-Type': 'application/json' },
  data: JSON.stringify({ key: 'value' }),
  responseType: 'json'
};

requester.send(request).then(response => {
  console.log(response);
}).catch(error => {
  console.error(error);
});

Handling Response and Errors

This feature demonstrates how to handle responses and errors from HTTP requests. The code sample shows how to log the response or error to the console.

const { createNodeHttpRequester } = require('@algolia/requester-node-http');

const requester = createNodeHttpRequester();

const request = {
  method: 'GET',
  url: 'https://example.com',
  headers: {},
  data: null,
  responseType: 'json'
};

requester.send(request).then(response => {
  console.log('Response:', response);
}).catch(error => {
  console.error('Error:', error);
});

Other packages similar to @algolia/requester-node-http

FAQs

Last updated on 28 Dec 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc