Skip to content
Snippets Groups Projects
Verified Commit dcbeb572 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: add callback configuration to restapi

parent d99fee22
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,7 @@ class RestAPI extends Server {
* @property {Object} write.init={} An options object containing any custom settings that you want to apply to the request. The parameters are identical to those of the {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request|Request constructor}
* @property {string} write.init.method=POST
* @property {Object} write.init.headers Object containing any custom headers that you want to apply to the request.
* @property {string} write.responseCallback Callback function to be executed after the request has been completed.
* @property {string} write.acceptedStatus=[200,201]
* @property {string} write.url URL
* @property {Object} write.mapping the mapping is applied before writing.
......@@ -74,6 +75,7 @@ class RestAPI extends Server {
init: {
method: "POST",
},
responseCallback: undefined,
acceptedStatus: [200, 201],
url: undefined,
mapping: {
......@@ -92,6 +94,7 @@ class RestAPI extends Server {
init: {
method: "GET",
},
responseCallback: undefined,
acceptedStatus: [200],
url: undefined,
mapping: {
......@@ -115,9 +118,12 @@ class RestAPI extends Server {
if (!isObject(init)) init = {};
if (!init["method"]) init["method"] = "GET";
return fetchData.call(this, "read", (obj) => {
let callback = self.getOption("read.responseCallback");
if(!callback) callback = (obj) => {
self.set(self.transformServerPayload.call(self, obj));
});
};
return fetchData.call(this, "read", callback);
}
/**
......@@ -139,7 +145,8 @@ class RestAPI extends Server {
let obj = self.prepareServerPayload(self.get());
init["body"] = JSON.stringify(obj);
return fetchData.call(this, init, "write");
let callback = self.getOption("write.responseCallback");
return fetchData.call(this, init, "write", callback);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment