+
+

Lab 4: Directly Govern your Omni Channel API (Optional)

Overview

API management is essential to an API-Led architecture as it provides a governance framework to your APIs in all three layers. You saw in Lab 1 how MuleSoft can proxy your existing APIs on an API Gateway that is used for enforcing policies and collecting data for analytics.

One unique and powerful feature of MuleSoft is that we can apply governance directly to a MuleSoft implemented API. With governance directly on the service we eliminate the additional hop through an API gateway, and we provide last mile security directly on the service.

The API we will use to demonstrate this is an Omni Channel API that you deployed earlier.

We will use another unique feature of MuleSoft - API auto-discovery. The API auto-discovery capability is used in a Mule application to enable API management from Anypoint Platform on the application HTTP endpoint. When you run an app that incorporates auto-discovery, the auto-discovery process registers and starts the app in API Manager. Registration and start up occurs without user intervention. Your API will be discovered and governed whether it is running on your laptop, on-premise or in the cloud.

Clients will continue to access your deployed Omni Channel API through the same HTTP endpoint. API Manager will manage, control access and monitor the usage of the API, which we will look at in the succeeding labs.

Step 1: Create the API in the API manager

We are going to use the Omni Channel API to implement the API.

  1. Navigate to the API Manager page, click on Add API and select Add new API.

    module 5 lab 4 ap apimanager configureEndpoint
  2. Select Mule Gateway as your runtime, and check the Deploy a proxy application

  3. . Configure with the following information:

    1. Proxy Type: Connect to existing application (basic endpoint)

    2. Runtime version: Select 4.4.0 (or the latest version available) property will define the Proxy URL and the name of the Mule application in the Runtime Manager.

  4. Click Next button

    module 5 lab 4 ap apimanager runtime
  5. Choose the Select API from Exchange and select Omni Channel Experience API

    module 5 lab 1 ap apimanager api select
  6. Check the values at the bottom of the screen to match

    1. Asset type: Select from the drop down list RAML/OAS.

    2. API version: Select from the drop down list 1.0.0.

    3. Asset version: Select from the drop down list 1.0.0.

  7. Then press Next

    module 5 lab 1 ap apimanager api settings
  8. Configure the API with the following information:

    1. API instance Label: <username>-impl-omni-channel. This Parameter is going to be used to identify the API in the API Manager.

      module 5 lab 4 api manager confgured
  9. Press Next and to check your configuration:

    module5 lab4 api confguration
  10. If your configurations is correct and press Save

    After pressing the save button, a screen with the API configuration will appear. Take note of the API ID. It will be used to configure the autodiscovery component.

    module5 lab4 api config saved

Step 2: Return to the complete Omni Channel Project in Anypoint Studio

  1. In case you already downloaded the complete Omni Channel Project in Anypoint Studio ona previous module, open that project in Studio. Then proceed to Step 3: Enable API Pairing with the Anypoint Platform.

    module 5 lab 1a studio
  2. If you have not downloaded it on a previous module, the following steps will detail how to download the complete Omni Channel Project from Exchange into Studio.

  3. Start Anypoint Studio from the desktop icon.

    module5 lab4 studio logo
  4. When you open the Studio for the first time, you are going to be asked for the workspace where the projects are going to be saved. Select the workspace displayed by default.

    module5 lab4 open workspace
  5. From Studio open exchange

    module5 open exchange
  6. Filter by Examples

  7. Select the sub organization

  8. Click on the omni-channel-api

    module5 example omni
  9. In the portal press Open

    module5 open portal

Once opened, the project will be imported into Studio.

module5 project imported

Step 3: Enable API Pairing with the Anypoint Platform

Your application must have the correct client credentials for your organization in order to be auto-discovered.

  1. On the Anypoint platform select Access Management

  2. Select Business Groups from the left menu

  3. Choose the workshop Business Group

    module5 lab4 select environment
  4. Select Environments

  5. Select Sandbox

    module5 lab4 organization
  6. You use the client_id and client_secret in Studio for API pairing. To show the client_secret click on Show.

    module5 lab4 sandbox env
  7. Back in Anypoint Studio, we need to go to Preferences from the main menu (on a Mac it’s under Anypoint Studio→*Preferences*. In Windows it’s under Window→*Preferences*). Search for and select API Manager. Copy and paste the client_id and client_secret in the client credentials fields. Check that they are correct by clicking Validate. Click Apply and Close.

    module5 lab4 pairing

Step 4: Create the API Autodiscovery Global Element

  1. Click on the Global Elements tab just at the bottom of the Canvas.

    module5 lab4 global elements
  2. Click on Create

    module5 lab4 create
  3. Using the Filter, search for auto and select API Autodiscovery and click OK

    module5 lab4 autodiscovery
  4. Fill in the API Id and Flow Name.

    To get this value, we need to get the information from the API Manager.

    1. Go to the API Manager and look for the API you created on the Step 1.

      module5 lab4 select api
      The API is in Unregistered state because it hasn’t been paired yet.
    2. Take note of the API ID

      module5 lab4 api details
  5. Complete the API ID with the API ID obtained in the last step.

  6. Select api-main for Flow Name

  7. Click OK

    module 5 lab4 autodiscovery fields

    You should see the new API autodiscovery global element. Save your project.

    module 5 lab4 studio2

Step 5: Test that the Application is Pairing Correctly with API Manager

  1. Start your application in test mode (you might have learned how to do it ona previous module). After your application has started correctly, go to API Manager and see if your API Status is now Active. This may take a minute.

    module 5 lab 1a test active
  2. Congratulations! Your Omni Channel application will now be governed by API Manager whether it’s running in test mode, on-premise or in the cloud.

Step 6: Redeploy Your API Omni Channel Application

  1. Redeploy your application.

    In case you need to select an environment, choose Sandbox
    module5 lab4 studio3
  2. Ensure that your application has successfully redeployed using Anypoint Runtime Manager. The status should go from Updating to Started

    module 5 lab 1a redeployed

    When you see Your application is started you can continue.

  3. Check in API Manager again that the API Status is Active (as in Step 4). You should see the green Deploy Successful in the status bar.

Summary

In this lab, we completed the following steps:

  • Create the API in the API manager>>

  • Complete Omni Channel Project in Anypoint Studio

  • Enable API Pairing with the Anypoint Platform

  • Create the API Autodiscovery global element

  • Test that the Application is Pairing Correctly with API Manager

  • Redeploy Your API Omni Channel Application

We saw how easy it is to enable your applications to be auto-discovered. This provides a simplified approach to manage MuleSoft impLemented APIs across your environment, whether on-premise or in the cloud. You are able to secure and govern your MuleSoft applications without an additional hop through a separate API Gateway. This also provides "last mile security" as policies are applied directly at the engine level. In this lab, we saw how we can deploy our API to CloudHub which can significantly speed up your deployment without having to manage and maintain infrastructure.

For further reading on deploying an API gateway and proxying your API, please refer to the following documentation:

module 5 lab 1a summary diagram

The next (optional) lab will show you how to proxy a legacy API that is not in Exchange.

Please proceed to Lab 5 if you wish.

If not…​

Congratulations! You have completed this Module.

Please proceed to next Module

Submit your feedback!
Share your thoughts to help us build the best workshop experience for you!
Take our latest survey!