Step 5. Deploy the API to CloudHub

Now that you’ve created and tested the Mule app that contains your new API from within Studio, let’s deploy the API to CloudHub. First, we’ll create an API proxy, which then enables us to test the API from Exchange. Then, we’ll then set up a rate-limiting policy to protect our API from a denial-of-service attack.

Step 5.1: Deploy API to CloudHub

To deploy this API in the form of a Mule app:

  1. From Studio, in the Mule Design perspective, right-click the hello-world project in Package Explorer, and then select Anypoint Platform > Deploy to CloudHub.

  2. If prompted, enter your Anypoint Platform username and password and click Sign in.

    dialog for deploying to CloudHub

  3. You must be in your account’s sandbox to deploy the API. If you see Design instead of Sandbox:

    1. Click Design to launch the Switch Environment dialog.

    2. Click Sandbox.

    3. Click Switch.

  4. Enter hello-world-greeting-firstname-lastname; every app and API name must be unique across CloudHub. This example uses hello-world-greeting-sandy-kim.

  5. Verify that Deployment Target is CloudHub.

  6. Don’t change any of the other default values.

  7. Click Deploy Application. After a brief pause, a window displays the status of the deployment.

  8. Click Open in Browser to see the status displayed in Runtime Manager.

    Runtime Manager displaying app deployment status

    When the project has been successfully deployed, Runtime Manager displays the status Started.

  9. To test the API deployment, send a request from Advanced Rest Client:

    1. Click Started to display the App url.

    2. Copy the value: hello-world-greeting.sandy-kim.us-e2.cloudhub.io for this example.

    3. In Advanced Rest Client, send a request to the base URI that you just copied. Be sure to add the API endpoint /greeting:

      GET http://hello-world-greeting.sandy-kim.us-e2.cloudhub.io/api/greeting
    4. If you see 200 OK and the greeting you specified, Today the greeting is Hello., then you have successfully deployed the API you created.

Now we need to create an API proxy application for this API, to restrict access and keep the service protected. We’ll add a rate-limiting policy, which we can do this while the API is running.

Step 5.2: Create an API Proxy Application

In order to add a rate limit policy to our deployed API, we must first add our API to API Manager, and create an API proxy.

  1. Log in to Anypoint Platform.

  2. Click API Manager.

  3. Switch to the sandbox environment.

  4. Click Manage API > Manage API from Exchange.

  5. Enter hello and select hello-world from the drop-down. Note you are working with the API, not the deployed app named hello-world-greeting.

  6. Verify the following values are selected:

    • Asset type: RAML/OAS

    • API version: v1

    • Asset version: 1.0.1

    • Managing type: Endpoint with Proxy

    • Proxy deployment target: CloudHub

    • Mule version: Check the checkbox for Mule 4

    • Implementation URI: http://hello-world-greeting-sandy-kim.us-e2.cloudhub.io/api. This is the same value as the App url from Step 1, with /api appended.

    • You can ignore TLS context since our API simply returns a hard-coded value.

    • Path: /

    • Ignore Advanced options.

  7. Click Save.

API Manager shows you a status page for your new proxy.

status page for API before proxy

Now that our API is managed in API Manager, we can create a proxy in the next step.

Step 5.3. Configure the API Proxy

To create a proxy for the API:

  1. If you aren’t on the API Manager hello-world API settings page from the previous step, navigate there:

  2. Click API Manager.

  3. Click hello-world to open the drop-down.

  4. Click v1 to display the proxy settings page.

  5. In the top section:

    • Click Add a label.

    • Enter No policy and press Return to save the label.

  6. In the Deployment Configuration section:

    • Select Runtime version: 4.2.2 or a later version if available.

    • For Proxy application name, which is the name displayed in Runtime Manager, enter hello-world-greeting-proxy, but append your last name or other unique string to ensure the proxy name is unique. The deploy button won’t be enabled until you enter a valid value here.

    • Select Update application if exists.

  7. Click Deploy. A progress window displays.

  8. When deployment is complete, close the progress dialog to return to the settings page.

Now you have an implmentation URL that you don’t want to share with the world, and a proxy URL which will be safe to share with the world once we configure it.

settings page showing URLs

To configure the proxy:

  1. In the Proxy section, right-click the link after Proxy URL and copy the link.

  2. At the top of the page, click Add consumer endpoint.

  3. Paste in the link you just copied, and press Return to save the link.

Now you can test the proxy endpoint from Exchange:

  1. Click View API in Exchange.

    Exchange page for hello-world proxy

  2. Click API instances. You can see the Mocking Service version and the new proxy you just created in the Sandbox environment, labeled "no policy".

  3. On the left side, click /greeting to open, then click GET.

  4. On the right side, toward the top of the column, click Mocking Service to open the drop-down menu.

  5. Select Sandbox: No policy instance

  6. Click Send. The response should be 200 OK and the greeting Today the greeting is Hello.

Finish configuring the proxy:

  1. Click API instances to return to the list of API instances in Exchange.

  2. Select your API.

  3. Click Private and then choose Public.

Step 5.4: Add a Rate Limit Policy

To add a rate limit policy:

  1. Return to API Manager.

  2. Click hello-world.

  3. Click v1.

  4. In the navigation on the left, select Policies.

  5. Click Apply New Policy.

  6. Don’t change the default All Mule Versions.

  7. Scroll to locate Rate limiting (not Rate limiting - SLA based).

  8. Click Rate limiting, select 1.3.3, and click Configure Policy.

  9. In the Apply Rate limiting policy page, set the limit values:

    • # of Reqs: 3

    • Time Period: 1

    • Time Unit: Minute

  10. Select Expose Headers.

  11. Select Method & Resource conditions: Apply configurations to all API methods & resources

  12. Click Apply.

The new policy is displayed at the bottom of the Policies home page.

Change the API instance label so it reflects the fact that we now have a policy on the proxy:

  1. Click Settings.

  2. Click the edit pencil next to Label and change the value to Rate-limiting policy.

Test the new policy:

In Advanced Rest Client, send GET requests to the API proxy http://hello-world-greeting-proxy.us-e2.cloudhub.io/greeting (the consumer endpoint plus /greeting) multiple times, until you receive the response 429 Too Many Requests.

What’s Next

Now that your API is deployed as a Mule app to Mule in CloudHub, you can manage it using Anypoint Platform tools.

Developer Deep Dive

MuleSoft provides many deployment options, described in Deploy Mule Applications.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub