Package Exports
- http-request-plus
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (http-request-plus) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
http-request-plus
Small wrapper around {http,https}.request()
Features:
- HTTP & HTTPs
- promise oriented
- stream oriented
- cancelable via cancel token or
response.cancel() - request
bodycan be either a buffer/string or a stream - content length header automatically set if available
- support
pathname&query(string or object) if nopathprovided - handle redirects (
maxRedirects = 5) - response emits
erroron abort and timeout
Install
Installation of the npm package:
> npm install --save http-request-plusUsage
Example
Easiest use case: just downloads and prints a page with error handling.
ES2015 - ES2016:
import httpRequestPlus from "http-request-plus";
(async () => {
try {
console.log(
await httpRequestPlus("http://example.org", {
onRequest(request) {
// this function will be called multiple times in case of redirections
request.setTimeout(10 * 1e3);
request.on("timeout", request.abort);
},
}).readAll("utf8")
);
} catch (error) {
console.error("An error as occured", error);
}
})();ES5:
var httpRequestPlus = require("http-request-plus").default;
httpRequestPlus("http://example.org")
.readAll("utf8")
.then(body => {
console.log(body);
})
.catch(error => {
console.error("An error as occured", error);
});HTTP method helpers
httpRequestPlus.delete();
httpRequestPlus.head();
httpRequestPlus.patch();
httpRequestPlus.post();
httpRequestPlus.put();httpRequestPlus.extend(opts)
const githubRequest = httpRequestPlus.extend("https://github.com");
githubRequest.post("/api");httpRequestPlus(options...) → Promise<response>
Promise<response>.cancel()
Promise<response>.readAll() → Promise<buffer>
response.cancel()
response.readAll() → Promise<buffer>
response.length
error.code
error.response
Development
# Install dependencies
> npm install
# Run the tests
> npm test
# Continuously compile
> npm run dev
# Continuously run the tests
> npm run dev-test
# Build for production (automatically called by npm install)
> npm run buildContributions
Contributions are very welcomed, either on the documentation or on the code.
You may:
- report any issue you've encountered;
- fork and create a pull request.
License
ISC © Julien Fontanet
