10.0.2 • Published 2 years ago
basic-browser-request v10.0.2
basic-browser-request
Another lightweight wrapper around XHR that — according to me — does just enough. Supports chunking, canceling, and JSON.
Installation
npm install basic-browser-request
Usage
var request = require('basic-browser-request');
var requestHandle = request(
{
url: 'http://something.whatever/yeah',
method: 'GET',
mimeType: 'text/plain',
onData: function onData(data) {
console.log(data);
chunksReceived += 1;
}
},
done
);
function done(error, response, text) {
if (error) {
console.log(error);
}
else {
useCompleteDownloadedText(text);
}
}
To cancel:
requestHandle.cancelRequest();
If you don't specify a mimeType, it defaults to application/json
and done()
will be passed a parsed JSON object.
In the interest of sort-of compatibility with request, the callback will be passed three parameters:
- error: An error object, if there was an error while making the request.
- response: An object containing the
statusCode
, thestatusMessage
,rawResponse
, andxhr
: XMLHttpRequest.response. This is not at all the same as a Node response, though, so proceed with caution. Thexhr
is the XMLHttpRequest used to run the request operation. - body: This is going to be a string or, if the mimeType was
application/json
, an object.
Tests
Run in Chrome and Firefox with make test
.
License
MIT.
TODO
Add JSON test.
10.0.2
2 years ago
10.0.1
3 years ago
10.0.0
4 years ago
9.0.2
5 years ago
9.0.1
6 years ago
9.0.0
6 years ago
8.0.0
7 years ago
7.3.1
7 years ago
7.3.0
7 years ago
7.2.0
7 years ago
7.1.0
7 years ago
7.0.0
7 years ago
6.0.1
7 years ago
6.0.0
7 years ago
5.0.1
7 years ago
5.0.0
8 years ago
4.1.0
8 years ago
4.0.1
8 years ago
4.0.0
8 years ago
3.0.0
8 years ago
2.0.4
8 years ago
2.0.3
8 years ago
2.0.1
9 years ago
2.0.0
9 years ago
1.1.0
9 years ago
1.0.0
9 years ago
0.1.0
10 years ago