Skip to content

Basic Pipeline Development

TekMonks edited this page Mar 11, 2019 · 5 revisions

The best way to learn any programming concept is through a "Hello World". Following the time tested tradition this page demonstrates a basic "Hello World" API developed as an ASB flow.

Input The input to the API is the following input message

{name: "Any name"}

Output The output of the API is the following message

{response: "Hello Any name"}

The Hello World Pipeline

The code below implements this pipeline

{
	"flow": {
		"name":"Hello world REST API",
		"disabled": false
	},
	"listener": {
		"type":"rest_listener", 
		"isMessageGenerator": true,
		"host": "127.0.0.1",
		"port":9090,
		"url":"/hello",
		"allow_origin": "*",
		"timeout": 120000
	},
	"route0":{
		"type": "js",
		"dependencies":["listener"],
		"isAsync": false,
		"js":"message.content.response = `Hello ${message.content.name}`; delete message.content.name;"
	},
	"output": {
		"type":"rest_responder",
		"dependencies":["listener", "route0"]
	}
}

ASB pipelines are JSON objects themselves. The various building blocks of the flow listed above are documented below.

Flow

"flow": {
	"name":"Hello world REST API",
	"disabled": false
}

This block must be present at the start of the flow and identifies the flow. The name attribute is the name of the pipeline, and the disabled attribute is to mark the pipeline as enabled or disabled. Disabled pipelines are not executed by the ASB.

Listener

"listener": {
	"type":"rest_listener", 
	"isMessageGenerator": true,
	"host": "127.0.0.1",
	"port":9090,
	"url":"/hello",
	"allow_origin": "*",
	"timeout": 120000
}

This block in the flow above declares a REST listener. A REST listener listens for incoming REST API messages. The attributes are self explanatory, except isMessageGenerator.

The isMessageGenerator attribute is a special attribute which declares that particular node to be a message creator. Thus, the ASB runs this particular node even if there are no messages in the bus, which is exactly what a listener node should be doing as it will listen for external events, for example incoming API messages, and then pass those messages as a new message into the pipeline.

All ASB listeners are message generators and must have this attribute present and marked true. Otherwise the pipeline will never process any incoming message.

Clone this wiki locally