From d542854587016e500284dce2f5dd869ce23242a6 Mon Sep 17 00:00:00 2001 From: jasonkneen Date: Fri, 21 Apr 2017 16:26:47 +0100 Subject: [PATCH] added beforePut, beforeGet, beforeDelete --- reste.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/reste.js b/reste.js index ba2132b..c51a703 100644 --- a/reste.js +++ b/reste.js @@ -185,7 +185,6 @@ var main = function() { }; function send() { - // go log(args.params); @@ -195,26 +194,44 @@ var main = function() { } else { http.send(JSON.stringify(args.params)); } - } else { - http.send(); } } - if (args.method == "POST" && config.beforePost) { + args.params = args.params || {}; + + if (args.method == "POST" && typeof config.beforePost == "function") { // initialise empty params in case it's undefined - args.params = args.params || {}; config.beforePost(args.params, function(e) { + args.params = e; + send(); + }); + + } else if (args.method == "GET" && typeof config.beforeGet == "function") { + config.beforeGet(args.params, function(e) { args.params = e; + send(); }); - send(); - } else { + } else if (args.method == "PUT" && typeof config.beforePut == "function") { + config.beforePut(args.params, function(e) { + args.params = e; + send(); + }); + + } else if (args.method == "DELETE" && typeof config.beforeDelete == "function") { + + config.beforeDelete(args.params, function(e) { + args.params = e; + send(); + }); + + } else { send(); }