This module is an implementation of Node's native http
module for Cordova on Android.
It tries to match Node's API and behavior as closely as possible, but is still a work in progress and some features are not supported.
Why not use stream-http or cordova-plugin-advanced-http?
Like cordova-plugin-advanced-http
this plugin tries to avoid limitations with browser implementations like forced CORS
and missing client certificate authentication
, but it improves on it by using Node.js stream implementation, to allow for requests of virtually any size, as well as the resuse of existing libraries built for Node.js
This plugin is published on NPM and can be installed using Cordova CLI
cordova plugin add cordova-plugin-node-http
The intent is to have the same API as the client part of the Node HTTP module. The interfaces are the same wherever practical.
This module implements http.request
, http.get
, and most of http.ClientRequest
and http.IncomingMessage
, in addition to http.METHODS
, http.STATUS_CODES
and some https options (ca
, cert
and key
).
See the Node docs for how these work.
http.createServer
is not supported // TODO document other missing features
const http = window.CordovaNodeHttp;
http.get('https://jsonplaceholder.typicode.com/users', function (res) {
let users = '';
res.on('data', function (buf) {
users += buf.toString('utf8');
});
res.on('end', function () {
console.log(users)
});
})