GatewayScript Hello World
Jose Ramon Huerga Ayuso
Lead of Integration Engineering at Axpo | MuleSoft Ambassador | AWS Certified
It is surprisingly difficult to find in the documentation of IBM API Connect how to write a Hello World in GatewayScript. As every time I do a demo to a customer, I usually create an API from scratch, it is not uncommon for me to end writing a Hello World as a response for the API.
All you need is this code snippet. You can add any properties to the object 'response' to suit your needs:
var response = {};
response.output = 'Hello World';
session.output.write(response);
apim.output('application/json');
Just place that code in a GatewayScript policy:
And that's all. Once you add that API in a Product and that product is published in a catalogue, you can invoke to your API. You will get this output:
{
output: "Hello World"
}
I hope this code snippet is useful to you as well.