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

@algolia/requester-browser-xhr

Package Overview
Dependencies
Maintainers
3
Versions
244
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/requester-browser-xhr

Promise-based request library for browser using xhr.

  • 5.17.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8M
decreased by-0.01%
Maintainers
3
Weekly downloads
 
Created

What is @algolia/requester-browser-xhr?

@algolia/requester-browser-xhr is a JavaScript library designed to facilitate making HTTP requests in a browser environment using the XMLHttpRequest (XHR) API. It is particularly useful for applications that need to interact with web services or APIs, providing a simple and efficient way to handle HTTP requests and responses.

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

Basic GET Request

This feature allows you to make a basic GET request to a specified URL. The code sample demonstrates how to create a requester instance and use it to send a GET request, handling the response or any errors that may occur.

const { createBrowserXhrRequester } = require('@algolia/requester-browser-xhr');

const requester = createBrowserXhrRequester();

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

requester(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 instance and use it to send a POST request with data, handling the response or any errors that may occur.

const { createBrowserXhrRequester } = require('@algolia/requester-browser-xhr');

const requester = createBrowserXhrRequester();

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

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

Handling Response Headers

This feature allows you to access and handle response headers from an HTTP request. The code sample demonstrates how to create a requester instance and use it to send a GET request, then log the response headers.

const { createBrowserXhrRequester } = require('@algolia/requester-browser-xhr');

const requester = createBrowserXhrRequester();

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

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

Other packages similar to @algolia/requester-browser-xhr

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