mappersmith
Advanced tools
Comparing version 2.22.2 to 2.23.0
@@ -18,3 +18,3 @@ 'use strict'; | ||
/* global VERSION */ | ||
var version = exports.version = '2.22.2'; | ||
var version = exports.version = '2.23.0'; | ||
@@ -21,0 +21,0 @@ var configs = exports.configs = { |
@@ -15,2 +15,3 @@ 'use strict'; | ||
* @param {Object} obj.params | ||
* @param {Object} obj.queryParamAlias | ||
* @param {String} obj.bodyAttr - body attribute name. Default: 'body' | ||
@@ -27,2 +28,3 @@ * @param {String} obj.headersAttr - headers attribute name. Default: 'headers' | ||
this.params = obj.params; | ||
this.queryParamAlias = obj.queryParamAlias || {}; | ||
this.binary = obj.binary || false; | ||
@@ -29,0 +31,0 @@ |
{ | ||
"name": "mappersmith", | ||
"version": "2.22.2", | ||
"version": "2.23.0", | ||
"description": "It is a lightweight rest client for node.js and the browser", | ||
@@ -5,0 +5,0 @@ "author": "Tulio Ornelas <ornelas.tulio@gmail.com>", |
@@ -123,3 +123,7 @@ [![npm version](https://badge.fury.io/js/mappersmith.svg)](http://badge.fury.io/js/mappersmith) | ||
// There are no restrictions for dynamic segments and HTTP methods | ||
addComment: { method: 'put', path: '/blogs/{id}/comment' } | ||
addComment: { method: 'put', path: '/blogs/{id}/comment' }, | ||
// `queryParamAlias` will map parameter names to their alias when | ||
// constructing the query string | ||
bySubject: { path: '/blogs', queryParamAlias: { subjectId: 'subject_id' } } | ||
} | ||
@@ -170,2 +174,12 @@ } | ||
### <a name="aliased-parameters"></a> Renaming query parameters | ||
Sometimes the expected format of your query parameters doesn't match that of your codebase. For example, maybe you're using `camelCase` in your code but the API you are calling expects `snake_case`. In that case, set `queryParamAlias` in the definition to an object that describes a mapping between your input parameter and the desired output format. | ||
This mapping will not be applied to params in the URL. | ||
```javascript | ||
client.Blog.all({ subjectId: 10 }) // https://my.api.com/blogs?subject_id=10 | ||
``` | ||
### <a name="body"></a> Body | ||
@@ -172,0 +186,0 @@ |
@@ -77,2 +77,4 @@ 'use strict'; | ||
path: function path() { | ||
var _this2 = this; | ||
var path = this.methodDescriptor.path; | ||
@@ -100,3 +102,9 @@ | ||
var queryString = (0, _utils.toQueryString)(params); | ||
var aliasedParams = Object.keys(params).reduce(function (aliased, key) { | ||
var aliasedKey = _this2.methodDescriptor.queryParamAlias[key] || key; | ||
aliased[aliasedKey] = params[key]; | ||
return aliased; | ||
}, {}); | ||
var queryString = (0, _utils.toQueryString)(aliasedParams); | ||
if (queryString.length !== 0) { | ||
@@ -103,0 +111,0 @@ path += '?' + queryString; |
@@ -142,3 +142,3 @@ 'use strict'; | ||
* @param {Integer} extras.status - it will replace the current status | ||
* @param {String} extras.rawData - it will replace the current rawStatus | ||
* @param {String} extras.rawData - it will replace the current rawData | ||
* @param {Object} extras.headers - it will be merged with current headers | ||
@@ -145,0 +145,0 @@ * @param {Error} extras.error - it will be added to the list of errors |
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
111730
2152
1090