Nav

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. First go to the API Manager

  2. Click on Manage API and select Manage API from Exchange

  3. Configure the API with the following Configuration:

    1. API name: Omni Channel Experience API. Notice when you start to write the name, the field is autocompleted.

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

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

    4. Managing type: Select Basic Endpoint.

    5. Implementation URI: leave it blank.

    6. Advanced options

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

        module5 lab4 config api
  4. 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 Module 2, Lab 2 you downloaded the complete Omni Channel Project in Anypoint Studio. Open that project in Studio.

    module 5 lab 1a studio

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 Environments from the left menu

    module5 lab4 select environment
  3. Select Sandbox

    module5 lab4 organization
  4. 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
  5. Back in Anypoint Studio select 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 Name and API Version.

    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. See Module 2, Lab 2, Step 4 if you need a reminder on how to do this. 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 using the same steps as you did in Module 2, Lab 3. Note that you should see and check Overwrite Existing Application when re-deploying.

    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:

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 Module 5.

Please proceed to Module 6