GET http://hello-world-greeting.sandy-kim.us-e2.cloudhub.io/api/greeting
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, you can deploy the API to CloudHub. First, create an API proxy, which then enables you to test the API from Exchange. Then, set up a rate-limiting policy to protect your 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:
-
From Studio, in the Mule Design perspective, right-click the
hello-world-app
project in Package Explorer, and then select Anypoint Platform > Deploy to CloudHub. -
If prompted, enter your Anypoint Platform username and password and click Sign in.
-
You must be in your account’s sandbox to deploy the API. If you see Design instead of Sandbox:
-
Click Design to launch the Switch Environment dialog.
-
Click Sandbox, and then click Switch.
-
-
In Deploying Application, enter
hello-world-greeting-firstname-lastname
for the app name. Every app and API name must be unique across CloudHub. This example useshello-world-greeting-sandy-kim
. -
For Deployment Target, select CloudHub.
-
Don’t change any of the other default values.
-
Click Deploy Application. After a brief pause, a window displays the status of the deployment.
-
Click Open in Browser to see the status displayed in Runtime Manager.
When the project is successfully deployed, Runtime Manager displays the status Started.
-
To test the API deployment, send a request from Advanced Rest Client:
-
Click Started to display the App url.
-
Copy the app URL value, which in this case is
hello-world-greeting.sandy-kim.us-e2.cloudhub.io
. + This URL is also be used later when you configure the proxy API. + -
In Advanced Rest Client, send a request to the base URI that you just copied. Be sure to add the API endpoint
/api/greeting
: -
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 you need to create an API proxy application for this API, to restrict access and keep the service protected. You will add a rate-limiting policy, which you can do while the API is running.
Step 5.2: Create and Deploy an API Proxy Application
You must add your API to API Manager and create an API proxy before you add a rate limit policy to your endpoint.
-
Log in to Anypoint Platform.
-
Click API Manager.
-
Click Sandbox to switch to the sandbox environment.
-
Select Add API > Add new API.
-
In the New API page, select Mule gateway and select the following values:
-
For Proxy type, select Deploy a proxy application.
-
For Target type, select CloudHub.
-
-
For Proxy app name, which is the name displayed in Runtime Manager, enter hello-world-greeting-proxy and append your last name or another unique string to ensure the proxy name is unique, and then click Next.
-
Click Select API from Exchange if it’s not already selected.
-
In the Select API search box, enter
hello
and select hello-world-api from the drop-down. Here, you are working with the API, not the deployed app namedhello-world-greeting
. -
Leave the following default values and click Next.
-
Asset type: RAML/OAS
-
API version: v1 (Latest)
-
Asset version: 1.0.0
-
-
In the Downstream page, accept the defaults and click Next.
-
In the Upstream page, enter the upstream URL, and click Next.
The upstream URL is the App url from the deployed app in Runtime Manager.
-
Click Next.
-
Review the selections for the API instance, and then click Save & Deploy.
-
After the API instance is deployed, a confirmation message appears with a link to Anypoint Runtime Manager. Click the link to view the details of your API instance
Now that your API is managed in API Manager, you can create a proxy in the next step.
Step 5.3. Configure the API Proxy
Now you have an implementation URL that you don’t want to share with the world, and a proxy URL that is safe to share with the world after you configure it.
To configure the proxy:
-
In Anypoint Manager > API Administration, click the hello-world-api link.
-
In API Summary, right-click the Proxy URL link and copy it.
-
Click the pencil icon to edit the API instance.
-
In the Downstream section, paste the link you just copied to Consumer endpoint, and then click Save & Apply.
Now you can test the proxy endpoint from Exchange:
-
Select Actions > View API in Exchange.
-
Click the Expand icon, then click Manage versions.
You can see the Mocking Service version and the new proxy you just created in the Sandbox environment.
-
Click Close.
-
Click /greeting to open, then click GET.
-
In Select server, expand the menu and select Sandbox - v1:<version>:
-
Click Send. The response should be
200 OK
with the greetingToday the greeting is Hello.
Finish configuring the proxy:
-
Click Home to return to the API summary.
-
Click Share.
-
In the Share dialog, click Public and then select the API version to make available on the public Exchange portal:
-
Click Save.
Step 5.4: Add a Rate Limit Policy
To add a rate limit policy:
-
Return to API Manager.
-
In API Administration, click the hello-world-api link.
-
In the navigation, click Policies.
-
Click Add policy.
-
Scroll to the Quality of service section, select Rate limiting (not Rate limiting - SLA based), and click Next.
-
In the Configure Rate limiting policy page, set the rate limit values:
-
Number of Requests:
3
-
Time Period:
1
-
Time Unit: Minute
-
-
Select Expose Headers.
-
In the Advanced options section, select the latest version.
-
Select Method & Resource conditions: Apply configurations to all API methods & resources, and then click Apply.
The new policy is displayed on the Policies home page.
Change the API instance label so it reflects the fact that you now have a policy on the proxy:
-
In the navigation, click API Summary.
-
Click the pencil icon and change the value for Instance Label to
Rate-limiting policy
. -
Click Save & Apply.
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.