Chapter 3. Using Ballerina: A Sample Application

This section describes how to use Ballerina efficiently to produce sleek, readable code. The example presented comes from a small but fully functional service that carries out one tiny part of an online retail store: finding information about products in a customer order. Here are some of the features illustrated by this small application:

  • Cooperating services

  • Asynchronous calls to external services

  • RESTful web communication

  • Database access

  • Error handling

  • Format conversion, particularly involving JSON

The application is made up of the following parts:

Store service

This receives an order ID over the web and returns a record containing various information such as the name, price, and inventory stock of each product. To do so, this service queries the Order service.

Order service

This receives an order ID from the Store service and returns a record containing information about each product in the order. To do so, this service queries a database, the Product service, and the Inventory service.

Product service

This receives a product ID from the Order service and returns a record containing the name and price of that product. To do so, this service queries the same database as the Order service.

Inventory service

This receives a product ID from the Order service and returns a record containing the stock (number of available items for that product). To do so, this service queries the same database as the Order and ...

Get Ballerina: A Language for Network-Distributed Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.