axway-flow-sdk
SDK for implementing custom flow nodes for API Builder flows
Features
- CLI tool for starting a new flow-node project
- SDK for building custom modules for API Builder flows
Install
npm install -g axway-flow-sdk
Generating a new flow-node project
Generates a new flow-node project named "mynode" in the current directory.
axway-flow -n mynode
cd mynode
npm install
npm run build
encodeURI example
const sdk = require('axway-flow-sdk');
exports = module.exports = sdk.init(module)
.add('encodeURI', {
name: 'Encode URI',
icon: 'encode.svg',
description: 'URI encoder'
})
.method('encode', {
name: 'Encode URI',
description: 'Encodes a URI by replacing each instance of certain characters with UTF-8 encodings.'
})
.parameter('uri', {
type: 'string',
description: 'The URI to encode.'
})
.outputs('encoded', {
name: 'Encoded',
description: 'The encoded URI.',
conext: '$.encodedURI',
schema: {
type: 'string'
}
})
.action((req, cb) => {
cb.encoded(null, encodeURI(req.params.uri));
});
Type references
In Axway API Builder,
it is possible to reference other types. For example, types can be loaded from ./schemas
, registered
from models, or registered
from service connectors. Any registered schema can be referenced whenever a schema
is required.
.parameter('greeting', {
"$ref": "schema://model/appc.arrowdb/user"
})
.outputs('next', {
schema: {
"$ref": "schema://model/appc.arrowdb/user"
}
})
Testing your flow-node module
The cli will automatically generate a unit test in ./test/test.js
. The test will use mocknode
to mock an API Builder flow-node.
mocknode(specs) : function
Mocks an API Builder flow-node using the spec generated with NodeBuilder
.
Access: public
Param | Type | Description |
---|
specs | NodeBuilder | The NodeBuilder object. |
Testing a successful output callback: cb.next(null, 'stuff')
This example uses mocha and promises to check that the spec is defined well enough
to pass the argument foo
to the method method
. It also mocks the callback
using the spec's defined output
, and ensures that the method invokes the correct
callback.
const specs = require('../src');
const { mocknode } = require('axway-flow-sdk');
it('describes a test', () => {
const args = { foo: undefined };
return mocknode(specs).node('example').invoke('method', args)
.then((response) => {
expect(response).to.deep.equal({
next: [null, 'stuff']
})
});
})
Testing an error default callback: cb('invalid argument')
This example is similar to the previous example, save that the expectation is that
the method will invoke cb('invalid argument')
when given an undefined
parameter.
const specs = require('../src');
const { mocknode } = require('axway-flow-sdk');
it('describes a test', () => {
const args = { foo: undefined };
return mocknode(specs).node('example').invoke('method', args)
.then((response) => {
expect(response).to.deep.equal(['invalid argument'])
});
})
API Reference
ERROR, Cannot find module.
Author
Axway support@axway.com https://axway.com
License
This code is closed source and Confidential and Proprietary to Axway, Inc. All Rights Reserved. This code MUST not be modified, copied or otherwise redistributed without express written permission of Axway. This file is licensed as part of the Axway Platform and governed under the terms of the Axway license agreement. Your right to use this software terminates when you terminate your Axway subscription.