diff --git a/application/source/data/datasource/server/restapi.mjs b/application/source/data/datasource/server/restapi.mjs index d4eaa2d9dc4b036263f3374ce03d3397bcf6081e..174a0b2ec0153d45da742fab97b9f4708a41efa4 100644 --- a/application/source/data/datasource/server/restapi.mjs +++ b/application/source/data/datasource/server/restapi.mjs @@ -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); } /**