processRequest() { this.logRequestInfo(); this.route(); } route() { const path = this.url.path(); if (path === '/testing123') this.testing123(); else log(`URL Path not handled: ${path}`); } testing123() { const model = new TestingTesting123(); this.serve(model.getResults()); } serve(results) { //serve in JSON format const res = this.response; res.writeHead(statusCodes.OK, jsonType); res.end(JSON.stringify(results)); }
function callApi() {
const
apiUrl = 'http://localhost:3000/testing123';
dataRecr = new DataReceiver(Controller.showApiResult);
https
.get(apiUrl, dataRecr.getReadDataFct())
.on("error", errorCallback);
}
//entry point to this code
callApi();
static showApiResult(results) { //we use stringify here as it produces a user friendly string log(JSON.stringify(results)); }