@request/api
Advanced tools
+16
-10
| module.exports = (config, submit) => { | ||
| module.exports = (config, custom) => { | ||
@@ -7,3 +7,3 @@ return ((options) => { | ||
| function wrapVerb (key) { | ||
| function wrapMethod (key) { | ||
| return (url) => { | ||
@@ -16,7 +16,7 @@ options.method = key.toUpperCase() | ||
| Object.keys(config.verb).forEach((key) => { | ||
| api[key] = wrapVerb(key) | ||
| Object.keys(config.method || {}).forEach((key) => { | ||
| api[key] = wrapMethod(key) | ||
| config.verb[key].forEach((alias) => { | ||
| api[alias] = wrapVerb(key) | ||
| config.method[key].forEach((alias) => { | ||
| api[alias] = wrapMethod(key) | ||
| }) | ||
@@ -32,3 +32,3 @@ }) | ||
| Object.keys(config.option).forEach((key) => { | ||
| Object.keys(config.option || {}).forEach((key) => { | ||
| api[key] = wrapOption(key) | ||
@@ -41,6 +41,12 @@ | ||
| api.submit = submit.bind(options) | ||
| function wrapCustom (key) { | ||
| return custom[key].bind(api, options) | ||
| } | ||
| config.custom.submit.forEach((alias) => { | ||
| api[alias] = submit.bind(options) | ||
| Object.keys(config.custom || {}).forEach((key) => { | ||
| api[key] = wrapCustom(key) | ||
| config.custom[key].forEach((alias) => { | ||
| api[alias] = wrapCustom(key) | ||
| }) | ||
| }) | ||
@@ -47,0 +53,0 @@ |
+1
-1
| { | ||
| "name": "@request/api", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "description": "Sugar API for @request/core consumers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+25
-11
@@ -12,8 +12,9 @@ | ||
| // all API methods and their aliases | ||
| var config = { | ||
| // HTTP verb methods | ||
| verb: { | ||
| // HTTP methods | ||
| method: { | ||
| get: ['select'] | ||
| }, | ||
| // option methods | ||
| // @request/core option methods | ||
| option: { | ||
@@ -25,2 +26,3 @@ qs: ['where'], | ||
| custom: { | ||
| check: [], | ||
| submit: ['gimme'] | ||
@@ -30,16 +32,28 @@ } | ||
| function submit () { | ||
| // `this` contains the options object that you usually pass to @request/core | ||
| return client(this) | ||
| // custom method implementation | ||
| var custom = { | ||
| // `host` is parameter passed to your method | ||
| check: function (options, host) { | ||
| if (/localhost/.test(host)) { | ||
| options.url += ':6767' | ||
| } | ||
| // `this` contains the API itself, for chaining purposes | ||
| return this | ||
| }, | ||
| // `options` contains the generated options object from the preceding methods | ||
| submit: function (options) { | ||
| // the last method should return a @request/core consumer | ||
| return client(options) | ||
| } | ||
| } | ||
| var request = api(config, submit) | ||
| var request = api(config, custom) | ||
| // GET http://localhost:6767?a=b | ||
| request | ||
| .select('http://localhost:6767') | ||
| .select('http://localhost') | ||
| .check('localhost') | ||
| .where({a: 'b'}) | ||
| .done((err, res, body) => { | ||
| // aaa | ||
| // mazing | ||
| // request callback | ||
| }) | ||
@@ -46,0 +60,0 @@ .gimme() |
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
12877
5.2%40
14.29%72
24.14%1
Infinity%