Giter Site home page Giter Site logo

aspyrx / node-http-xhr Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 3.0 42 KB

Node.js XMLHttpRequest implementation using http.request()

JavaScript 100.00%
nodejs node npm npm-package npm-module http https xhr xmlhttprequest xmlhttprequest-wrapper javascript js request http-request http-requests

node-http-xhr's Introduction

node-http-xhr

npm

Build Status

An implementation of XMLHttpRequest for node.js using the http.request API.

Motivation

This package was written to provide the XMLHttpRequest API to test browser code that is being tested in a node.js environment.

Installation

npm install --save node-http-xhr

Usage

// Standalone usage
var XMLHttpRequest = require('node-http-xhr');

// Usage as global XHR constructor
global.XMLHttpRequest = require('node-http-xhr');


var req = new XMLHttpRequest();

// Event handlers via .on${event} properties:
req.onreadystatechange = function() {
  console.log('readyState: ' + req.readyState);
};

// or using .addEventListener(event, handler):
req.addEventListener('load', function() {
  console.log('response: ' + req.response);
});

req.open('GET', 'https://github.com/aspyrx', true);
req.send();

Note about browser environments

If you use a bundler like browserify or webpack that follows the browser field in package.json, the module will simply export window.XMLHttpRequest. This is provided for sake of compatibility.

Development

Documentation

To generate documentation:

npm run doc

The html documentation will be placed in doc/.

Tests

npm test

Known issues

Currently, some features are lacking:

  • Some ProgressAPI events (loadstart, loadend, progress)
  • responseType values other than '' or 'text' and corresponding parsing
    • As a result of the above, overrideMimeType() isn't very useful
  • setRequestHeader() doesn't check for forbidden headers.
  • withCredentials is defined as an instance property, but doesn't do anything since there's no use case for CORS-like requests in node.js right now.

node-http-xhr's People

Contributors

aspyrx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.