allcount / allcountjs

Rapid application development framework for Node.js
http://allcountjs.com
MIT License
402 stars 83 forks source link

Call Rest APIs from allcountjs #143

Open bdqnghi opened 7 years ago

bdqnghi commented 7 years ago

I have some existing Rest APIs that provide some information and I want to integrate Allcountjs with my APIs, how can I call it from inside an AllcountJS app?

roginvs commented 7 years ago

I solved this with hack: First, I added into node_modules/allcountjs/core/index.js few lines:

//In the beginning
var request = require('request');
...
function configure() {
    .... 
    injection.bindFactory('Request', function () {
        return request;
    });

Then, in configuration file:

        beforeSave: function (Entity, Crud, Console, ValidationError, Request) {
          return new Promise(resolv => {
          Request.get('http://127.0.0.1:5555', x => {
            resolv();
          })
        })
roginvs commented 7 years ago

Or better read this https://github.com/allcount/allcountjs/blob/master/docs/customizing.md