funcional
v0.2.0-alpha.3
Published
Simplify working with Google Cloud Platform functions
Downloads
3
Readme
funcional
Requires node version 8.x.x
. The compatibility of this library should match the node LTS release schedule, since that is the version used by Google Cloud Functions.
Remote
Should be used in the remote cloud function.
The constructor can be initiated with a handler
and an optional options
object.
The handler function should be declared as async
or return a Promise
. It takes the arguments instance
and an object composed of the original http request and response.
Sample usage
index.js hosted on Google Cloud Functions:
const Remote = require('funcional/remote');
const handler = async (instance) => {
const body = instance.body;
return { formatted: body.name.toUpperCase().split(' ').join('-') };
};
exports.http = new Remote(handler).handle;
Local
To be used on the server-side and communicate with the remote function.
Sample Usage
const Local = require('funcional/local');
const local = new Local({
region: 'example-gcp-region',
project: 'example-project',
name: 'example-function-name'
});
const communicate = async (data) => {
try {
const response = await local.send(data);
console.log(response); // holds the response body from the function
console.log(local.meta); // meta holds meetadata from the execution of the remote function
} catch (error) {
// ... handle error
}
};
communicate({ name: 'James Dean' });
// { formatted: 'JAMES-DEAN' }