Created
January 22, 2018 00:15
-
-
Save niradler/a604452722af6e1e1819271d787b8daa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Server(config) { | |
this.url = config.url; | |
this.actions = config.actions; | |
for (const key in this.actions) { | |
Server.prototype[key] = function(param,data) { | |
var host = this.url.concat(this.actions[key].path); | |
var find_var = host.indexOf(':'); | |
if (find_var>-1 && arguments.length>0) { | |
for (var i = 0; i < arguments.length; i++) { | |
var name=Object.getOwnPropertyNames(arguments[i])[0], | |
value=arguments[i][name]; | |
host = host.replace(':' + name,value) | |
} | |
} | |
var options ={ | |
method: this.actions[key].method, | |
url: host, | |
} | |
if(['post','put'].indexOf(this.actions[key].method.toLowerCase())>-1) | |
options.data=data?data:{}; | |
return axios(options); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment