Saturday, May 4, 2024
HomeProgrammingEngineering Apps for Reuse: A Sensible Instance Utilizing Slack, MuleSoft, and Salesforce...

Engineering Apps for Reuse: A Sensible Instance Utilizing Slack, MuleSoft, and Salesforce | by Dave Norris | Sep, 2022


Design, construct, deploy, and monitor APIs

ASCII artwork. The API to reuse throughout Slack and Salesforce | picture by creator

This text describes the method of designing and constructing an API that may be reused throughout Slack and Salesforce. It demonstrates easy methods to create a easy slash command in Slack and a Circulation in Salesforce to transform textual content to ASCII artwork.

Repurposing an present API to attach completely different techniques is one key metric that drives productiveness and helps scale back prices inside an organisation.

Let’s say we’re tasked with creating an interactive expertise for customers in Slack. We need to present a slash command that enables customers to specify some textual content and have our utility convert that textual content into ASCII artwork.

There are three questions we should always take into consideration;

  1. Are there present programming libraries that I can reuse?
  2. Is there an present API I can reuse?
  3. What number of purchasers may need to use this function?

Step one was to design an API specification that may take a message as an enter and output ASCII artwork.

Through the use of MuleSoft’s Anypoint Platform I can’t solely design the API specification however share it internally to make it discoverable by others wanting so as to add comparable performance to their apps.

Anypoint Design — Creating API specs

My subsequent job was to resolve if there have been present programming libraries that may assist me.

MuleSoft functions are based mostly on Java and as one of the crucial extensively adopted programming languages worldwide, I discovered numerous Java lessons that would assist me.

Now, Slack slash instructions count on inputs and outputs to be in a Slack-specific format. As an alternative of encapsulating all of the logic in a single API name, I’ll cut up the textual content to ASCII conversion right into a separate API that may be reused.

ascii-art-sapi might be based mostly on our API specification. Designed to be reused.

slack-ascii-art-xapi will orchestrate and remodel messages for Slack. Briefly, it should convert ASCII artwork to one thing that appears good in Slack.

Creating two APIs to set us up for fulfillment

To display the power to reuse APIs we’ll additionally use the ascii-art-sapi to create the power to transform textual content to ASCII in Salesforce.

On this case, we’ll use Exterior Providers to transform the API specification to invocable Apex that we will use immediately in a Circulation.

Reusing APIs throughout two completely different experiences

ascii-art-sapi

For the construct part, we’re utilizing MuleSoft’s Anypoint Studio. This offers connectors, processors, and modules that enable me to implement the API logic in much less time than writing code.

Since MuleSoft compiles to a Java utility I can embody the jfiglet library as a dependency.

Together with jfiglet as a dependency

Utilizing a Remodel Message module permits me to make use of the above Java class to rework an enter to ASCII.

I can import the Java class from the dependency after which merely use the strategies inside. On this case, convert a given string to ASCII characters.

Importing third-party libraries and calling their strategies

We are actually able to deploy the API.

slack-ascii-art-xapi

For the slack-specific logic, we’ll construct the next:

Slack-specific logic encapsulated into a brand new API

This API will obtain the enter from the Slack slash command and instantly publish it to a queue to course of it asynchronously.

The asynchronous listener will then name the present ascii-art API to transform the textual content from the slash command into ASCII earlier than sending the message again to a Slack channel.

So, it seems like this:

Slash command — ascii-art

Okay, so we now have a functioning Slack slash command. Let’s have a look at getting this expertise into Salesforce.

Since we now have the ascii-art API designed we will use Exterior Providers to import the specification into Salesforce.

Named credentials are wanted in Salesforce to offer the endpoint and authorisation particulars for the Anypoint Platform and ascii-art API.

From Salesforce navigate to Setup->Exterior Providers and stroll by the wizard. On this instance, we hook up with the MuleSoft Anypoint Platform in order that Salesforce can discover and create Apex lessons to name our ASCII artwork endpoint.

Creating an Exterior Service in Salesforce

Now that we now have the Exterior Service created we will use declarative instruments to invoke the API. On this instance, we’ll use Circulation.

Circulation mechanically consists of the motion wanted to make use of the API we imported utilizing Exterior Providers. We supplied a display for a person to specify the textual content to transform to ASCII and, within the instance, above we save the output to a subject on the Contact object.

On the finish of the configuration, your person expertise ought to seem like the next:

Salesforce Circulation calling an API endpoint utilizing Exterior Providers

One of many key parts to engineering apps for reuse is the power to design, construct, deploy, handle and monitor APIs.

MuleSoft’s Anypoint Platform affords the power to just do that. Couple that energy with Slack and Salesforce and you may engineer some nice experiences.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments