Comparing version 1.0.15 to 1.0.16
@@ -43,3 +43,2 @@ 'use strict'; | ||
*/ | ||
// eslint-disable-line | ||
@@ -71,2 +70,33 @@ | ||
/** | ||
* make an http POST request | ||
* @param {string} url - url or path to call | ||
* @param {RequestOptions} options | ||
* @returns {Promise} | ||
* @example | ||
* ```js | ||
* const http = require('http-call') | ||
* await http.post('https://google.com') | ||
* ``` | ||
*/ | ||
static async post(url, options = {}) { | ||
options.method = 'POST'; | ||
let http = new this(url, options); | ||
await http.request(); | ||
return http.body; | ||
} | ||
parseBody(body) { | ||
if (!this.headers['Content-Type']) { | ||
this.headers['Content-Type'] = 'application/json'; | ||
} | ||
if (this.headers['Content-Type'] === 'application/json') { | ||
this.requestBody = JSON.stringify(body); | ||
} else { | ||
this.requestBody = body; | ||
} | ||
this.headers['Content-Length'] = Buffer.byteLength(this.requestBody).toString(); | ||
} | ||
/** | ||
* make a streaming request | ||
@@ -119,2 +149,4 @@ * @param {string} url - url or path to call | ||
this.path = u.path || this.path; | ||
if (options.body) this.parseBody(options.body); | ||
this.body = undefined; | ||
} | ||
@@ -141,2 +173,3 @@ | ||
request.on('error', reject); | ||
if (this.requestBody) request.write(this.requestBody); | ||
request.end(); | ||
@@ -143,0 +176,0 @@ }); |
{ | ||
"name": "http-call", | ||
"description": "make http requests", | ||
"version": "1.0.15", | ||
"version": "1.0.16", | ||
"author": "Jeff Dickey @dickeyxxx", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/dickeyxxx/http-call/issues", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11489
151
3