Learn how to use the AsyncAPI contract with cloud-native programming language Ballerina to benefit your API development

Ballerina AsyncAPI tool

How Ballerina will support your AsyncAPI contract

  • x-ballerina-event-identifier — For the identify the event type of the event when receiving an event from an event source. This can be type or path.
  • x-ballerina-event-type — this is for naming the events inside the channel.

Generate the Ballerina source file related to the AsyncAPI triggers and run the below command

bal asyncapi -i <yaml contract>
  • data_types.bal: This file contains all the Ballerina data types extracted from the AsyncAPI definition under the components schema section.
  • service_types.bal: This file contains implementation for all the service types relevant to the event API described in the AsyncAPI definition under the channel sections.
  • listener.bal: this contains the HTTP listener, which listens to the relevant third-party service. (API providers)
  • dispacther_service.bal: this contains the event dispatching logic which is documented in the contract.
  1. Make sure to place all the generated files inside the ballerina package before running the generated files. (If you want to make the current folder with the ballerina package, run `bal init` inside the folder to make `Ballerina.toml`. )
  2. Then create another ballerina file naming `service.bal` and place the below ballerina code with your logic implementation.


In this article, we had a quick look at AsyncAPI specification and How Ballerina can add value to your asyncAPI contract. You can learn more about the Ballerina AsyncAPI tool here. Give a try to use AsyncAPI tool and make your coding life easy. Happy reading… !



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sumudu Nissanka

Sumudu Nissanka

Software Engineer @wso2 | Graduate @University of Colombo School of Computing | Former DevOps intern @wso2