Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
xhr-request
Advanced tools
Readme
An extremely tiny HTTP/HTTPS request client for Node and the browser. Uses xhr in the browser and simple-get in Node.
Supported response types: JSON, ArrayBuffer, and text (default).
For streaming requests, you can just use simple-get directly. It works in Node/browser and supports true streaming in new versions of Chrome/FireFox.
npm install xhr-request --save
A simple example, loading JSON:
var request = require('xhr-request')
request('http://foo.com/some/api', {
json: true
}, function (err, data) {
if (err) throw err
// the JSON result
console.log(data.foo.bar)
})
Another example, sending a JSON body
with a query
parameter. Receives binary data as the response.
var request = require('xhr-request')
request('http://foo.com/some/api', {
method: 'PUT',
json: true,
body: { foo: 'bar' },
responseType: 'arraybuffer',
query: {
sort: 'name'
}
}, function (err, data) {
if (err) throw err
console.log('got ArrayBuffer result: ', data)
})
There are a lot of HTTP clients, but most of them are Node-centric and lead to large browser bundles with builtins like url
, buffer
, http
, zlib
, streams, etc.
With browserify, this bundles to 7kb minified. Compare to 742kb for request, 153kb for got, 74kb for simple-get, and 25kb for nets.
req = xhrRequest(url, [opt], [callback])
Sends a request to the given url
with optional opt
settings, triggering callback
on complete.
Options:
query
(String|Object)
headers
(Object)
json
(Boolean)
responseType
defaults to 'json
' and body
will be sent as JSONresponseType
(String)
'text'
, 'arraybuffer'
or 'json'
'text'
unless json
is truebody
(String|JSON)
json
is truemethod
(String)
'GET'
timeout
(Number)
The callback
is called with the arguments (error, data, response)
error
on success will be null/undefineddata
the result of the request, either a JSON object, string, or ArrayBuffer
response
the request response, see belowThe response object has the following form:
{
statusCode: Number,
method: String,
headers: {},
url: String,
rawRequest: {}
}
The rawRequest
is the XMLHttpRequest in the browser, and the http
response in Node.
Since opt
is optional, you can specify callback
as the second argument.
req.abort()
The returned req
(the ClientRequest or XMLHttpRequest) has an abort()
method which can be used to cancel the request and send an Error to the callback.
MIT, see LICENSE.md for details.
FAQs
tiny http client for Node and the browser
The npm package xhr-request receives a total of 234,660 weekly downloads. As such, xhr-request popularity was classified as popular.
We found that xhr-request demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.