I want to access my REST backend and show some JSON data in a Webix Datatable.
- The backend requires authentication *AND*
- I need to change the received JSON data before showing it in the datatable.
How do I archive both? I know about the Webix REST proxy. I also found a solution to send the “Authroizsation” HTTP header. But how do I chain/combine that with the JSON reformatting?
I have several rest endpoints in the backend. All of them shall be shown in Datatables. All of them need authentication. But they all need DIFFERENT kinds of reformatting.
This is my current approach:
webix.proxy.authenticatingProxy = webix.extend({
load: function(view, callback){
var url = view.config.url.source;
var token = 'Basic ' + btoa(username + ':' + password) // btoa - base64 encoding
console.log("GET", url, "Headers:", token)
webix.ajax().headers({
"Authorization" : token
}).get(url).then(function(data){
console.log("GET ", url,"returned", data.json())
var records = data.json();
webix.ajax.$callback(view, callback, "", records, -1);
}).catch(logHttpError)
}
}, webix.proxy.rest);
/* Proxy for fetching ideas from server
BUT THIS IS NOT CHAINED YET. DOES NOT CALL authenticating Proxy
*/
webix.proxy.ideasProxy = webix.extend({
load: function(view, callback){
var ideasUrl = "http://localhost:8080/liquido/v2/laws/search/findByStatus?status=IDEA";
console.log("GET ideas")
//view.config.url.source = ideasUrl
webix.ajax().get(ideasUrl).then(function(data){
var ideas = data.json()._embedded.laws;
console.log("GET ideas returned", ideas)
webix.ajax.$callback(view, callback, "", ideas, -1);
}).catch(logHttpError)
}
}, webix.proxy.authenticatingProxy);