Socket
Socket
Sign inDemoInstall

xhr2-cookies

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xhr2-cookies

XMLHttpRequest polyfill for node.js


Version published
Weekly downloads
141K
increased by3.67%
Maintainers
1
Weekly downloads
 
Created

What is xhr2-cookies?

The xhr2-cookies npm package is a fork of the 'xhr2' package that adds support for cookies. It provides an XMLHttpRequest implementation for Node.js, allowing you to make HTTP requests and handle cookies in a similar way to how you would in a browser environment.

What are xhr2-cookies's main functionalities?

Making HTTP GET Requests

This feature allows you to make HTTP GET requests. The code sample demonstrates how to create an XMLHttpRequest object, open a connection to a URL, and handle the response.

const XMLHttpRequest = require('xhr2-cookies').XMLHttpRequest;
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.example.com/data', true);
xhr.onload = function () {
  if (xhr.status >= 200 && xhr.status < 300) {
    console.log(xhr.responseText);
  }
};
xhr.send();

Handling Cookies

This feature allows you to handle cookies in your HTTP requests. The code sample demonstrates how to enable credentials (cookies) in the XMLHttpRequest object.

const XMLHttpRequest = require('xhr2-cookies').XMLHttpRequest;
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.example.com/data', true);
xhr.withCredentials = true;
xhr.onload = function () {
  if (xhr.status >= 200 && xhr.status < 300) {
    console.log(xhr.responseText);
  }
};
xhr.send();

Making HTTP POST Requests

This feature allows you to make HTTP POST requests. The code sample demonstrates how to create an XMLHttpRequest object, set the request headers, and send data in the request body.

const XMLHttpRequest = require('xhr2-cookies').XMLHttpRequest;
const xhr = new XMLHttpRequest();
xhr.open('POST', 'https://api.example.com/data', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function () {
  if (xhr.status >= 200 && xhr.status < 300) {
    console.log(xhr.responseText);
  }
};
xhr.send(JSON.stringify({ key: 'value' }));

Other packages similar to xhr2-cookies

Keywords

FAQs

Package last updated on 14 Nov 2017

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