This package has been deprecated

Author message:

this package has been deprecated

xrequest

3.3.3 • Public • Published

xrequest

HTTP requests with advanced redirects, charset detection, early termination, and no dependencies.

Usage

npm install xrequest
xrequest("http://www.example.com", function(err, res, body){
	console.log(body.toString())
})

API

xrequest(options, callback)


options

options can be a URL string or an object with these fields:

basic

  • 'url' (string, required): url string.

  • 'method' (string, default: "GET"): http method.

  • 'headers' (object, default: {}): http headers.

  • 'body' (string or buffer, default: undefined): entity body for PATCH, POST and PUT requests.

redirects

  • 'followRedirect' (boolean, default: true): follow HTTP 3xx responses as redirects.

  • 'maxRedirects' (number, default: 3): the maximum number of redirects to follow.

  • 'followCanonicalRedirect' (boolean, default: false): follow canonical headers and tags as redirects.

  • 'followRefreshRedirect' (boolean, default: false): follow refresh meta tags as redirects.

  • 'followJavascriptRedirect' (boolean, default: false): follow Javascript location changes as redirects.

encoding

  • 'encoding' (string, default: undefined): encoding of response data. If undefined or null, the body is returned as a Buffer. If detect, the body is still returned as a Buffer, but the res object will have extra fields for HTML responses: charset and charsets.

  • 'gzip' (boolean, default: true): request and receive compressed content encodings from the server.

safety

  • 'timeout' (number, default: undefined): number of milliseconds to wait for a response to end, undefined means to limit.

  • 'rejectUnauthorized' (boolean, default: false): requires SSL certificates be valid.

size

  • 'bodyMinLength' (number, default: undefined): minimum response body size in bytes, undefined means to limit.

  • 'bodyMaxLength' (number, default: undefined): maximum response body size in bytes, undefined means to limit.

  • 'bodyAllowPartial' (boolean, default: false): return truncated body for responses exceeding the bodyMaxLength limit.

type

  • 'responseCodeFilter' (number or array, default: undefined): only accept responses with the provided status codes, undefined means to limit.

  • 'responseTypeFilter' (string, default: undefined): only accept responses matching (or containing) the provided MIME type sub string, undefined means to limit.

  • 'responseAllowEmptyType' (boolean, default: false): accept responses without MIME types while responseTypeFilter is enabled.

  • 'responseSignatureFilter' (string or array, default: undefined): only accept responses with the provided byte signatures, undefined means to limit.


callback

callback returns the response object as the second argument res with these fields:

  • 'headers' (object): the response headers.

  • 'statusCode' (number): the response status code.

  • 'elapsed' (number): total time usage in milliseconds.

  • 'complete' (boolean): true if the response body is complete.

  • 'charset' (string): the best guess of the HTML charset, requires encoding = "detect".

  • 'charsets' (array): all charset candidates with confidence scores, requires encoding = "detect".

  • 'redirected' (number): total redirected times.

  • 'redirects' (array): full redirect history.

  • 'href' (string): the last URL (after all redirects).

  • 'address' (string): remote IP address.

License

(The MIT License)

Copyright (c) 2016-2017 Yichao 'Peak' Ji

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i xrequest

Weekly Downloads

55

Version

3.3.3

License

none

Last publish

Collaborators

  • npm