Skip to content

Commit

Permalink
added beforePut, beforeGet, beforeDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkneen committed Apr 21, 2017
1 parent 485eb3c commit d542854
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions reste.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ var main = function() {
};

function send() {

// go
log(args.params);

Expand All @@ -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();
}

Expand Down

0 comments on commit d542854

Please sign in to comment.