If you are an Azure solution architect, you shouldn't miss out on what Azure Logic Apps has to offer.
Azure Logic Apps could be used by a developer or any tech-savvy individual to automate workflows or business processes through a user-friendly visual design interface. It also provides many built-in connectors that could be utilised to connect apps and services together.
In this blog post, I'm going to demonstrate how I use Azure Logic Apps, Bing Maps service API and Azure Table storage to expose a Proxy API without writing or deploying any code.
An airport needs to show an estimated travel time from the city to the airport and from the airport to the city on its website.
Backend developer to implement a proxy API that connects to a cloud-based maps service to return the travel duration as well as route legs to the front-end applications.
A serverless function needs to make a call to get data from the maps service API every five minutes and then, store the data in a simple storage service.
The proxy API needs to retrieve the data from the storage service and return it in an HTTP response.
The solution to this task is to set up two Azure Logic Apps (following single responsibility design pattern):
The store routes app has the following operations:
A Recurrence (Schedule) trigger with the interval set to five minutes:
Connect to the Bing Maps service to get data using the connector and supply a Free Basic or Enterprise API key
Insert data to Azure Table storage:
Azure Table storage is a service that stores structured NoSQL data in the cloud, providing a key/attribute store with a schemaless design. Access to Table storage data is fast and lower in cost than traditional SQL. Azure Table storage is chosen to provide a simple storage solution for the proxy API data. To set up the connection, you need to supply the storage account name and key as well as the table name to the action:
The service supports key/value pairs over simple types. There are some options for simulating complex types. In this example, I utilise the Compose (Data Operations) action in Azure Logic Apps to flatten the complex JSON object being returned from the Bing Maps Routes API endpoint. This action requires an input taken from the Bing Maps output in the previous action so you can use the function
Finally, the Insert or Merge Entities action can be used to insert data into the Azure Table storage. This action requires the following input parameters: Partition Key (
guid()), Row Key (
guid()) and the simple JSON data composed in the previous action.
The retrieves routes app has the following operations:
A HTTP request trigger with an HTTP method (GET/POST). Take note of the generated URL that can be used to call the API later:
Get all entities from the Azure Storage Table by providing the connection name and the table name:
Get a single latest entity from the list of entities by adding the following operations to the workflow (You can skip this step if you always overwrite the data with the same Partition Key and Row Key in the Store Routes workflow):
Use the Select (Data Operations) action to get an array of entity timestamp integer:
Use the Filter array (Data Operations) action to filter only the entity with the latest timestamp using the
A response operation needs to use the list of entities output in the previous action as the input and send the Body property of the first entity to the output by entering a custom function:
The Store Routes Logic App will call the Bing Maps API and insert the data into the Azure Table storage every five minutes:
The Retrieve Route Logic App will be executed to retrieve a single latest entity from the Azure Table storage upon an HTTP request. The endpoint URL can be found in the HTTP request trigger action after the workflow is saved.
Thanks to Azure Logic Apps, I can now get the expected results that give me the travelDuration (in seconds), the travelDistance (in Kilometres) as well as the details of the itinerary to use in the front-end application:
I'm so happy as I can accomplish my goals without writing or deploying any code. It's so easy for both a developer and a tech-savvy individual to use Azure Logic Apps for automating workflows and connecting with other services and APIs.
I'd also recommend you learn how to store and manage values by using variables in Azure Logic Apps and how to create a custom connector in Azure Logic Apps from Microsoft documentation.
Also, check out this article for a comparison of Azure Logic Apps and Azure Functions.
Thanks for reading! 🎉