Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
httpplease
Advanced tools
There are a lot of JS libraries for making HTTP requests in JavaScript. Why use this one? Because it's awesome, that's why. And this is why it's awesome:
browserify and webpack users can simply npm install httpplease
.
Bower users can bower install httpplease
.
<script>
tag fans can grab the standalone build from the "browser-builds"
directory.
Minified and gzipped, the standalone browser build is <2K.
httpplease.get('http://example.com', function(err, res) {
// Do something with the result.
});
Alternatively, you can pass a request options object as the first parameter:
httpplease.get({url: 'http://example.com'}, function(err, res) {
// Do something with the result.
});
If you'd rather include the method in the object, that's okay too:
httpplease({method: 'GET', url: 'http://example.com'}, function(err, res) {
// Do something with the result.
});
You can create a new http function with default request object values:
var http = httpplease.defaults({method: 'GET', errorOn404: false});
http('http://example.com', function(err, res) {
// This request was made using the defaults specified above.
});
The request object supports the following properties:
Name | Description |
---|---|
url | The URL to request. |
method | The HTTP method to use for the request. |
body | The body to send with the request. |
headers |
An object containing HTTP headers to send, for example:
{Accept: '*/*'} .
|
errorOn404 |
A boolean specifying whether a 404 response should be treated as an
error or not. Defaults to true .
|
In the event of an error, an error object will be passed as the first argument
to your callback. If the error is an HTTP error, it will have all of the
properties that a response object has (listed below), but will be a JS Error
object (which can be useful if relying on instanceof checks). It also has one
additional property—message
—which contains a description of the error.
The response object passed to your callback in the event of a successful request has the following properties:
status | The numeric status code. |
text | The raw response text. |
body | The processed response body. Depending on the content type of the response and the plugins being used, this may be the same as `response.text` (a string) or some other object (like a parsed JSON object). |
contentType | The content type of the response. |
headers | An object containing the parsed response headers. |
isHttpError | A boolean that specifies whether this object represents a server-reported HTTP error. This may be false—even on error objects—in the case of non-HTTP errors like XDomain failures or plugin errors. |
request | An object representing the request. |
xhr | The XHR or XDomain object used to make the request. |
httpplease supports plugins for changing how requests are made. Some plugins are built in:
Name | Enabled by Default? | Description |
---|---|---|
jsonparser | No |
Converts JSON responses into JS objects on
response.body .
|
cleanurl | Yes | Encodes unencoded characters in the request URL. Required by some browsers if you're using non-ASCII characters. |
oldiexdomain | No |
Enables cross domain requests in IE9 by (transparently) using the
XDomainRequest object when necessary.
|
oldieactivex | No | For super old versions of IE that didn't define XMLHttpRequest, use an ActiveX object. |
Plugins are enabled with the use
method:
var jsonparser = require('httpplease/lib/plugins/jsonparser');
httpplease = httpplease.use(jsonparser);
Or, if you're using the standalone build:
<script src="httpplease.js" type="text/javascript"></script>
<script src="httppleaseplugins.js" type="text/javascript"></script>
var jsonparser = httppleaseplugins.jsonparser;
httpplease = httpplease.use(jsonparser);
Notice that use
returns a new httpplease instance. This is so that you can
create multiple instances, each with their own plugins:
var http = httpplease.use(jsonparser);
http
.use(oldiexdomain)
.get('http://example.com', function(err, res) { ... }); // Uses "jsonparser" plugin and "oldiexdomain".
http.get('http://example.com', function(err, res) { ... }); // Only uses "jsonparser" plugin.
httpplease.get('http://example.com', function(err, res) { ... }); // No extra plugins are used.
You can use as many plugins as you want—either by passing multiple plugins to
use
or chaining calls:
var http = httpplease
.use(jsonparser, oldiexdomain, myPlugin)
.use(anotherPlugin);
In order to keep your builds as small as possible, most plugins aren't enabled
by default. (See the table above.) However, some small plugins are. If you
want to disable all plugins, use the bare()
method:
var http = httpplease.bare();
Like use()
, this method also returns a new httpplease instance so you can
continue to use the old object with the original plugins intact.
In addition to the bundled plugins, you can create your own. Plugins are simply objects that implement one or more of the following methods:
Method | Description |
---|---|
createXHR(req) | Creates an XHR object. The first plugin that return a non-null value from this method will be used. |
processRequest(req) | This method gives the plugin a chance to manipulate the request object before the request is made. For example, it can change the body or add headers. |
processResponse(res) | This method gives the plugin a chance to manipulate the response object before the callback is invoked. |
This project is mostly just a small wrapper around XMLHttpRequest and an (I hope) sensible structure for extending functionality. The reason it works on the server is because of driverdan's awesome node-XMLHttpRequest library—it's the secret sauce that makes the browser-focused design of httpplease possible!
FAQs
The polite HTTP request library for node and the browser
The npm package httpplease receives a total of 12,818 weekly downloads. As such, httpplease popularity was classified as popular.
We found that httpplease demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.