I'm getting started with Koa ecosystem. I know it's based in generator functions (a topic that is pretty new for me, for now), and I'm having issues with a very simple task: Call an external web service, fetch the response and send it to the client app (Angular in my case).
The code:
var koa = require('koa');
var app = koa();
var koarouter = require('koa-router');
var router = koarouter();
router.post('/devices', function *(next) {
var reqdata = {};
reqdata.info="request to send"
var options = {
url: url_getDevices,
headers: reqdata
};
var response = yield request(options);
var info = JSON.parse(response.body);
console.log(info);
});
I suppose that I have to manage with yield and next but I'm doing different tests and having issues, and I'd to know best practices with Koa in this case.
Thanks!