Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@algolia/requester-fetch

Package Overview
Dependencies
Maintainers
85
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/requester-fetch

Promise-based request library using Fetch.

  • 5.17.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
284K
decreased by-10.72%
Maintainers
85
Weekly downloads
 
Created

What is @algolia/requester-fetch?

@algolia/requester-fetch is a lightweight HTTP client built on top of the Fetch API. It is designed to be used with Algolia's JavaScript API clients but can be used independently for making HTTP requests in a straightforward manner.

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

Basic GET Request

This feature allows you to make a basic GET request to a specified URL. The response is returned as a promise, which can be handled using `.then` and `.catch`.

const { createFetchRequester } = require('@algolia/requester-fetch');

const requester = createFetchRequester();

requester({
  method: 'GET',
  url: 'https://jsonplaceholder.typicode.com/posts/1'
}).then(response => {
  console.log(response.content);
}).catch(error => {
  console.error(error);
});

POST Request with JSON Body

This feature allows you to make a POST request with a JSON body. You can specify the request method, URL, data, and headers.

const { createFetchRequester } = require('@algolia/requester-fetch');

const requester = createFetchRequester();

requester({
  method: 'POST',
  url: 'https://jsonplaceholder.typicode.com/posts',
  data: JSON.stringify({
    title: 'foo',
    body: 'bar',
    userId: 1
  }),
  headers: {
    'Content-type': 'application/json; charset=UTF-8'
  }
}).then(response => {
  console.log(response.content);
}).catch(error => {
  console.error(error);
});

Handling Response Headers

This feature allows you to access and handle response headers from the HTTP response. The headers can be accessed using the `.headers` property of the response object.

const { createFetchRequester } = require('@algolia/requester-fetch');

const requester = createFetchRequester();

requester({
  method: 'GET',
  url: 'https://jsonplaceholder.typicode.com/posts/1'
}).then(response => {
  console.log(response.headers.get('Content-Type'));
}).catch(error => {
  console.error(error);
});

Other packages similar to @algolia/requester-fetch

FAQs

Package last updated on 12 Dec 2024

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc