FAQS

How do I get headers or GET/POST params?

exports.endpoint = function(req, cb){...}

You can get headers from req object as req.headers. Params can be get using req.query for GET and req.body for POST.

Try printing out req object, then you will have a clear Idea.

How do I redirect?

You can redirect from callback using the following format.

cb(undefined, {location: "https://google.com/"})

How do I set headers for response?

Right now, you can't because backbench is a Faas. But we are working on to integrate an API gateway too.

There is a provision for modifying headers, it can be done by putting headers property in second argument of callback inside an object. Now for the response to send you need to have a body object.

cb(undefined, {headers: {}, body: {"key": "hello world"}})

Last updated