@capriza/http-utils
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -10,34 +10,39 @@ var axios = require('axios'); | ||
this.requestQueue = new Queue({ concurrency : options.maxConcurrent || 10000}); | ||
this.username = options.username; | ||
this.password = options.password; | ||
this.baseUrl = options.baseUrl; | ||
this.headers = options.headers || { | ||
this.http = axios.create({ | ||
baseURL: options.baseUrl, | ||
timeout: options.requestTimeout || 30000, | ||
auth : options.username && options.password && { username : options.username, password : options.password }, | ||
headers: options.headers || { | ||
"Accept": "application/json", | ||
"Content-Type": "application/json" | ||
}; | ||
} | ||
}); | ||
} | ||
async get(uri, params, body, priority) { | ||
return this._callRequest("get", uri, params, body, priority); | ||
async get(url, opts, priority) { | ||
return this._callRequest("get", url, opts, priority); | ||
} | ||
async put(uri, params, body, priority) { | ||
return this._callRequest("put", uri, params, body, priority); | ||
async put(url, opts, priority) { | ||
return this._callRequest("put", url, opts, priority); | ||
} | ||
async post(uri, params, body, priority) { | ||
return this._callRequest("post", uri, params, body, priority); | ||
async post(url, opts, priority) { | ||
return this._callRequest("post", url, opts, priority); | ||
} | ||
async downloadUrlAttachment(uri, priority) { | ||
var res = await this.get(uri, {responseType : 'arraybuffer'}, null, priority); | ||
var res = await this.get(uri, {responseType : 'arraybuffer'}, priority); | ||
return res && res.data && (new Uint8Array(res.data)); | ||
} | ||
async _callRequest(method, uri, params, body, priority){ | ||
async _callRequest(method, url, opts = {}, priority){ | ||
return new Promise((resolve, reject)=>{ | ||
let func = axios[method]; | ||
var doRequest = async ()=>{ | ||
let options = Object.assign(opts,{ | ||
url, | ||
method | ||
}); | ||
var doRequest = async ()=>{ | ||
return func(`${this.baseUrl}${uri}`, this._getRequestOpts(params, body)); | ||
return this.http.request(options); | ||
} | ||
@@ -62,18 +67,2 @@ | ||
} | ||
_getRequestOpts(opts, body){ | ||
let options = Object.assign({ | ||
headers : this.headers, | ||
data : body | ||
}, opts); | ||
if (this.username && this.password){ | ||
options.auth = { | ||
username: this.username, | ||
password: this.password | ||
} | ||
} | ||
return options; | ||
} | ||
}; |
{ | ||
"name": "@capriza/http-utils", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "HTTP Request utils that handles, request-response, errors, concurrency, priority and authentication", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
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
19550
193