0.3.3 • Published 5 years ago
flow-api-component v0.3.3
Flow API component
The component makes API requests and is designed to work with Flow SDK
To get started, install the package in your NodeJS project
npm i flow-api-component --save
Use the component as below
// require the component
const Component = require('flow-api-component');
// create instance of the GET component for example
const component = new Component.GET();
Provide url, headers and any data to pass
component.getProperty('URL').data = 'https://www.google.com/';
component.getProperty('Headers').data = {
'X-Requested-With': 'XMLHttpRequest'
};
component.getProperty('Data').data = {
'q': 'home'
};
Listen in for port emit events
component.getPort('Complete').onEmit(function() {
// request was successfully made
const port = this.getPort('Complete');
// the response can be accessed through properties of the port
const statusCode = port.getProperty('StatusCode').data;
const statusText = port.getProperty('StatusText').data;
const responseHeaders = port.getProperty('Headers').data;
const responseData = port.getProperty('Data').data;
// or the whole response object
const response = port.getProperty('Response').data;
});
component.getPort('Failed').onEmit(function() {
// an error occured
// the actual error can be accessed through the 'Data' property of the port
let err = component.getPort('Failed').getProperty('Data').data;
});
Execute the component
// add the component to a graph before executing it
const Graph = require('flow-platform-sdk').Graph;
new Graph("graph-1").addComponent(component);
component.execute();
Conclusion
That's the Flow API GET component. Also check, the POST, PUT, DELETE components.