Reputation: 540
So I was looking for a while now for a simple solution for this but couldn't find anything clear.
My goal is to receive HTTP Post request from html form to my KOA server and forward it to remote API.
As you can understand from the question, I'm complete beginer for not being able to do this, but my code so far looks like this:
var koaBody = require('koa-body')()
publicRouter.post('/file', koaBody,
function *(next) {
var post = this.request.body
console.log(post)
// augment post
}
)
Currently I'm able to receive file to the server and I do want to learn what should I add in comment line (I assume there) in order to augment post request with additional data, such as keys, signatures and content-type details.
So first of all, how should I create this augmented POST?
And how to forward it? I assume for that I can use promises (Q.denodeify(require('request'))), like I have been able to do it with GET request
Upvotes: 0
Views: 202
Reputation: 3041
Use co-request
(here) to send make remote API calls.
var request = require('co-request');
var koaBody = require('koa-body')();
publicRouter.post('/file', koaBody,
function *(next) {
var post = this.request.body
console.log(post)
yield request({
url: '/some/remote/api',
method: 'POST',
body: body
});
}
)
Upvotes: 1