rest-facade
Advanced tools
Comparing version 1.6.0 to 1.7.0
{ | ||
"name": "rest-facade", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Simple abstraction for consuming REST API endpoints", | ||
@@ -41,5 +41,6 @@ "main": "src/index.js", | ||
"change-case": "^2.3.0", | ||
"deepmerge": "^1.5.1", | ||
"superagent": "^3.5.2", | ||
"deepmerge": "^1.5.1" | ||
"superagent-proxy": "^1.0.2" | ||
} | ||
} |
@@ -149,3 +149,3 @@ # rest-facade [![Build Status](https://travis-ci.org/ngonzalvez/rest-facade.svg?branch=master)](https://travis-ci.org/ngonzalvez/rest-facade) | ||
> N.B. any properties in a given `options` object whose values are Functions will be ignored with regard to generating the query string. | ||
> N.B. any properties in a given `options` object whose values are Functions will be ignored with regard to generating the query string. | ||
@@ -203,5 +203,5 @@ ~~~js | ||
~~~js | ||
client.create({ firstName: 'John', lastName: 'Doe' }); | ||
client.create({ firstName: 'John', lastName: 'Doe' }); | ||
// The server will receive | ||
// The server will receive | ||
// { first_name: 'John', last_name: 'Doe' } | ||
@@ -213,3 +213,3 @@ ~~~ | ||
### Per-Request Customization | ||
Sometimes you need to do some customization to each individual request that is sent to the consumed API, | ||
Sometimes you need to do some customization to each individual request that is sent to the consumed API, | ||
a likely candidate is for adding request-specific headers. | ||
@@ -219,3 +219,3 @@ | ||
- defining a function in global options under `options.request.customizer` | ||
- defining a function in global options under `options.request.customizer` | ||
- passing in a options object to a method call that contains a "special" `_requestCustomizer` property (which should be a function as well!) | ||
@@ -227,2 +227,11 @@ | ||
### Proxy support | ||
If a proxy URI is provided, **all** requests will be sent through that proxy. | ||
```js | ||
// Rest client that sends all requests through a proxy server. | ||
var client = new rest.Client(url, { | ||
proxy: 'https://myproxy.com:1234' | ||
}); | ||
``` |
@@ -6,2 +6,3 @@ var extend = require('util')._extend; | ||
var request = require('superagent'); | ||
@@ -15,2 +16,5 @@ var Promise = require('bluebird'); | ||
// Add proxy support to the request library. | ||
require('superagent-proxy')(request); | ||
/** | ||
@@ -242,2 +246,3 @@ * @class | ||
var reqCustomizer = this.options.request.customizer; | ||
var proxy = this.options.proxy; | ||
var newKey = null; | ||
@@ -281,4 +286,10 @@ var value = null; | ||
// Set methods and attach the body of the request (if this is a POST request). | ||
var req = request[method](options.url).send(options.data); | ||
var req = request[method](options.url); | ||
if (proxy) { | ||
req = req.proxy(proxy); | ||
} | ||
req = req.send(options.data); | ||
// Add request headers. | ||
@@ -285,0 +296,0 @@ for (var header in headers) { |
@@ -20,4 +20,6 @@ module.exports = { | ||
} | ||
} | ||
}, | ||
proxy: null | ||
}; | ||
@@ -12,2 +12,4 @@ var extend = require('util')._extend; | ||
var request = require('superagent'); | ||
var domain = 'http://domain.com'; | ||
@@ -638,4 +640,20 @@ var endpoint = '/endpoint'; | ||
}, | ||
'should use the proxy defined in the global settings': | ||
function (done) { | ||
var proxy = 'https://proxyserver.com'; | ||
var client = this.client = new Client(domain + endpoint, { proxy: proxy }); | ||
var req = nock(domain).get(endpoint).reply(200); | ||
var spy = sinon.spy(request.Request.prototype, 'proxy'); | ||
client | ||
.getAll() | ||
.then(function(data) { | ||
expect(request.Request.prototype.proxy.calledWithMatch(proxy)).to.be.true; | ||
done(); | ||
}); | ||
}, | ||
} | ||
} | ||
}; |
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
46339
1047
233
5
222040
+ Addedsuperagent-proxy@^1.0.2
+ Addedagent-base@4.3.0(transitive)
+ Addedast-types@0.16.1(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedco@4.6.0(transitive)
+ Addeddata-uri-to-buffer@1.2.0(transitive)
+ Addeddebug@2.6.93.1.0(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addeddegenerator@1.0.4(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addedes6-promise@4.2.8(transitive)
+ Addedes6-promisify@5.0.0(transitive)
+ Addedescodegen@1.14.3(transitive)
+ Addedesprima@3.1.34.0.1(transitive)
+ Addedestraverse@4.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedftp@0.3.10(transitive)
+ Addedget-uri@2.0.4(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addedhttp-proxy-agent@2.1.0(transitive)
+ Addedhttps-proxy-agent@2.2.4(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedip@1.1.9(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addedms@2.0.0(transitive)
+ Addednetmask@1.0.6(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedpac-proxy-agent@2.0.2(transitive)
+ Addedpac-resolver@3.0.0(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedproxy-agent@2.3.1(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedraw-body@2.5.2(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedsmart-buffer@1.1.15(transitive)
+ Addedsocks@1.1.10(transitive)
+ Addedsocks-proxy-agent@3.0.1(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedsuperagent-proxy@1.0.3(transitive)
+ Addedthunkify@2.1.2(transitive)
+ Addedtoidentifier@1.0.1(transitive)
+ Addedtslib@2.8.1(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addedunpipe@1.0.0(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedxregexp@2.0.0(transitive)
+ Addedyallist@2.1.2(transitive)