Contact Us 1-800-596-4880

Lab 1: Proxy an existing Omni Channel API

Overview

API management is essential to an API-Led architecture as it provides a governance framework to your APIs in all three layers. For API Management to take place, we need to be able to host our APIs, both new and existing, on an API Gateway that will be used for enforcing policies and collecting data for analytics.

MuleSoft can apply governance directly to a MuleSoft implemented API or through a proxy gateway for these and other external existing APIs.

The APIs we will use are two versions of the Omni Channel API. You will create a proxy gateway to an already deployed mock implementation in this Lab 1.

In the optional Lab 4 we show how you can directly govern a MuleSoft service without a proxy, and the optional Lab 5 shows how you can proxy and govern existing services that were not developed in Design Center and published to Exchange.

In this lab, we will define an API that will act as a proxy for Mythical Corporation’s Omni Channel API. The proxy will be deployed to Anypoint Platform’s API Gateway, which is powered by the Mule runtime. The Mule run-time can run on-premise, on a private cloud or on the CloudHub service hosted by Anypoint Platform. In this scenario, we will be use the latter, CloudHub.

Clients will access the API through the API Gateway which will then forward the requests to the actual Omni Channel API Mock Implementation. Having the proxy deployed on the API gateway allows Anypoint Platform to manage, control access and monitor the usage of the API, which we will look at in the succeeding labs.

module 5 lab 1 summary diagram

Step 1: Go to API Manager

  1. In Anypoint Platform (https://anypoint.mulesoft.com), click the API Manager icon to start creating your API.

    module 5 lab 1 click apimanager
  2. You can also click on the top menu, on "APIs" and then on API Manager.

    module 5 lab 1 ap navigation apimanager
  3. select SANDBOX as the environment

height:300

Step 2: Configure an API Proxy

For this lab, we are going to configure the API as a proxy to Mythical Corporation’s Omni Channel API Mock Implementation. The API is available as an HTTP Restful API accessible through the base URL http://workshop-omni-channel-mock-service-v5.us-e1.cloudhub.io/api

Let’s take a look to the products resource of this API that returns product information when an HTTP GET is issued.

To see the all the resources of this API, you can view the API definition and Summary in Exchange

module 5 lab 1 apiconsole

To create the proxy we are going to get the API Definition from Exchange.

  1. Now let’s configure an API proxy gateway for this API. Navigate to the API Manager page, click on Add API and select Add new API.

    module 5 lab 1 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: Deploy aproxy application

    2. Target Type: Cloudhub 2.0 (you might need to change the space based on location)

    3. Runtime version: Select the latest version available

    4. Proxy application name: <username>-proxy-omni-channel. This property will define the Proxy URL and the name of the Mule application in the Runtime Manager.

    5. Leave the rest of the options in their default value.

  4. Click Next button

    module 5 lab 1 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 setting
  8. Configure the API with the following information:

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

    2. Base path: /

    3. Press Next

      module 5 lab 1 api manager confgured
    4. Upstream URL: http://workshop-omni-channel-mock-service-v5.us-e1.cloudhub.io/api

      module 5 lab 1 api manager confgured2
  9. Press Next and to check your configuration:

    module5 lab1 api confguration
  10. If your configurations is correct press Save & Deploy and deployment of the proxy will start.

    module 5 lab 1 proxy deploy

    You’ll see a blue popup next to the application name indicating the application is deploying. CloudHub is allocating a worker with 0.1 vCore to host your new proxy application. You will know it’s complete when a green icon appears. In the meantime, feel free to look around (view the Logs to see what’s going on).

    It can take anywhere from a few seconds to a few minutes to deploy the proxy. Good time to grab some coffee or explore the documentation.

  11. Once it is deployed, at the top of the page you will see the status of the API. It should be green with a green dot next to it, as shown below. This indicates that your API was successfully deployed and is now being managed.

    module 5 lab 1 ap apimanager proxypanel

The proxy you just created is a Mule application/project. If you want to see what is going on under the covers just download the proxy and import it into Anypoint Studio. Unlike the blackbox proxies of the “pure-play” API Management tools like Mashery, Layer 7, apigee… Anypoint proxies are Mule applications which you can download and extend with all the capabilities of Mule that you will learn about through the remaining labs.

If needed, you could augment the generated flow with additional logic.

While you deployed this proxy to an Runtime running on CloudHub, you could also deploy this proxy application to an on-premise Runtime or to a Runtime Fabric container.

Step 3: Test the API Proxy

Your proxy API is now accessible through CloudHub.

  1. Go to Runtime Manager and click your deployed API

    module 5 lab 1 api deployed

    You can get the exact URL of your hosted proxy from the Public Endpoint:

    module 5 lab 1 api url
  2. Right-click on the URL to copy it.

  3. Open POSTMAN module5 lab1 postman icon.

  4. Paste what you copied into the field that says Enter request URL but do NOT press enter yet.

  5. Add “/products/search” to retrieve the product information using your proxy.

    You should have a URL that looks like: http://{your_domain_name}/products/search

    module5 lab1 postman url config
  6. Go to the Headers tab

  7. Add the following values:

    key value

    Content-type

    application/json

    Accept

    application/json

    module5 lab1 postman header conf
  8. Now press Send and you should see the following:

    module 5 lab 1 browser product search response

You can also test the API by using any other REST Client. It’s important to set the headers after you do the request.

Summary

In this lab, we completed the following steps:

  • Overview of Anypoint API Manager

  • Configure the API proxy

  • Test the API proxy using Postman

We saw how easy it is to proxy existing APIs and deploy it on a CloudHub-based API Gateway. This provides a low friction approach to manage existing APIs across your environment. You are able to leverage a hybrid API Gateway service offering which can be on-premise or on the cloud. In this lab, we saw how we can deploy our API Gateway 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 1 summary diagram

Congratulations! You have completed Lab 1.

Please proceed to Lab 2