Routing Stage

Route the request to another destination according to the configured routing rules. Each routing rule includes a condition, a customized request, a destination, and a customized response.

Routing stage evaluates the routing rules by using the if...else if...else statement, like the following pseudo-code:

if condition 1 is true
	if pre-destination transformation exists
		do the transformation

	get the data from the destination
	
	if post-destination transformation exists
		do the transformation
else if condition 2 is true
	...
...

else
	get the data from the default destination

Note: A Microflow® application can contain only one Routing stage at the end of the request flow.

Configurations

Routing stage contains the following fields:

Field Description
Condition A condition expression is evaluated against the if statement of JavaScript. In the context of evaluation, a parameter req is available, with the query, params, headers and payload fields of the request object exposed.
REQUEST JavaScript code to process the request. The parameter passed to the custom JavaScript function is payload, which is the payload field of the request object. This behavior is the same as Transformation Stage in the request flow.
Destination A relative URL or an absolute URL of the destination. If a relative URL is provided, the original host, port, and protocol information is used to process the request. For example, if /pet is provided, the original host is petstore.cloud.tibco.com, port number is 2222, and protocol is http, the request with Routing stage applied is directed to http://petstore.cloud.tibco.com:2222/pet.
Note: Destinations that are a redirect are not supported. For example, if you use http://example.com/V1/Up and the destination server redirects it to https://example.com/V1/Up, you must enter https://example.com/V1/Up.
RESPONSE The parameter passed to the custom JavaScript function is body, which is the response data sent from the destination. This behavior is the same as Transformation Stage in the response flow.

Examples

The following sample code shows how to add a new status all to the GET/pet/findByStatus operation of the Petstore sample and redirect the pet/findByStatus?status=all request to http://petstore.swagger.io/v2/pet/findByStatus?status=available,pending,sold.

Condition

req.query.status && /all/.test(req.query.status)

Destination

/v2/pet/findByStatus?status=available,pending,sold

After pushing the configured stage and running the Microflow application, query <Microflow endpoint>/pet/findByStatus?status=all, the result is the same as querying <Microflow endpoint>/pet/findByStatus?status=available,pending,sold.