ganomede-base-client
Advanced tools
Comparing version
{ | ||
"name": "ganomede-base-client", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Simple wrapper for restify.JsonClient", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,7 +6,8 @@ # ganomede-base-client | ||
- single `request()`-like method (`#apiCall({method, path, body, headers, qs})`), meaning: | ||
- single `request()`-like method (`#apiCall({method, path, body, headers, qs}, callback)`), meaning: | ||
- base urls; | ||
- per request headers; | ||
- easier query string; | ||
- supports path prefixes (useful if you want to have something like `/api/v1` in front of all requests). | ||
- supports path prefixes (useful if you want to have something like `/api/v1` in front of all requests); | ||
- if `body` or `qs` contain `req_id` param, sets `x-request-id` header to value of it. | ||
@@ -13,0 +14,0 @@ ## Basic Usage |
@@ -34,2 +34,9 @@ 'use strict'; | ||
_extendedHeaders ({body, qs}) { | ||
const reqId = (qs || {}).req_id || (body || {}).req_id || null; | ||
return reqId | ||
? {'x-request-id': reqId} | ||
: {}; | ||
} | ||
apiCall ({method, path, headers = {}, body = null, qs = null}, callback) { | ||
@@ -39,9 +46,10 @@ this._checkArgs({method, path, headers, body, qs}); | ||
const formattedQs = qs ? `?${querystring.stringify(qs)}` : ''; | ||
const args = [{ | ||
const opts = { | ||
path: this.pathPrefix + path + formattedQs, | ||
headers | ||
}]; | ||
headers: Object.assign(this._extendedHeaders({body, qs}), headers) | ||
}; | ||
if (body) | ||
args.push(body); | ||
const args = body | ||
? [opts, body] | ||
: [opts]; | ||
@@ -48,0 +56,0 @@ return this.api[method](...args, (err, req, res, obj) => { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
70296
314.58%16
166.67%495
607.14%55
1.85%1
Infinity%