https://jsonplaceholder.typicode.com/
Getting Started with Managed Flex Gateway on CloudHub 2.0
The goal of this tutorial is to quickly get started with Anypoint Managed Flex Gateway deployed on CloudHub 2.0. The tutorial describes how to create and run Managed Flex Gateway.
Additionally, the tutorial describes how to publish an API that is secured with a basic authentication policy.
Before You Begin
Before getting started with Flex Gateway, ensure that you have:
-
Reviewed the Requirements and Limits for Flex Gateway and have the necessary managed Flex Gateway permissions.
-
Created a private space in CloudHub 2.0 or have access to a private space created by someone else. To create a private space, see Creating Private Spaces.
Deploy a Managed Flex Gateway
-
Log in to Anypoint Platform
with your Anypoint username and password.
-
Select Runtime Manager.
-
Click Flex Gateways in the side navigation panel.
-
Click Managed Flex Gateway.
-
Click Add Managed Flex Gateway.
-
Enter a Gateway name.
-
Select a your private space as your Deployment target.
-
Click Advanced options.
-
Copy and save the Managed Flex Gateway public endpoint for later testing. This is the HTTP or HTTPs URL that appears in the Public endpoint UI block, for example,
https://my-gateway-abc123.edf456.us-east1.anypoint.mulesoft.com/
. -
Click Save & deploy.
The UI returns to the dashboard of your new Managed Flex Gateway.
-
Wait until your gateway’s Status is Running.
Publish a Simple API
-
From your Managed Gateway’s dashboard, click Add API instance.
-
From the Add API page, select Flex Gateway as your runtime.
-
Select your deployed Managed Flex Gateway in the Select a gateway section.
-
Click Next.
-
Click Create New API.
-
Specify an API name and select HTTP API as the asset type.
-
Click Next.
-
Don’t configure any downstream options.
-
Click Next.
-
From the Upstream page:
-
Enter the following in the Upsream URL field:
-
-
Click Next.
-
Click Save & Deploy.
The UI takes you to the API Summary page of the newly created API instance.
All HTTP requests made to the public endpoint are now proxied to the
jsonplaceholder
service. -
To test the API instance, replace the public endpoint placeholder and run this command in a new terminal window:
curl -s -o /dev/null -w "%{http_code}\n" --request GET '<publicEndpoint>'
sshThe command executes a
GET
request to the API, and then prints the resulting200
status code, indicating success.
Secure Your API Using the Basic Authentication Policy
-
From the API Summary page, select Policies from the side navigation panel.
-
In the Policies page, click Add inbound policy.
-
Select the Basic Authentication - Simple policy.
-
Click Next.
-
For User Name, enter
user
. -
For User Password, enter
password
. -
Click Apply.
-
To test the API Instance without authentication, replace the public endpoint placeholder and run this command in the terminal window:
curl -s -o /dev/null -w "%{http_code}\n" --request GET '<publicEndpoint>'
sshThe command prints a resulting
401 (Unauthorized)
status code, because the request does not include the Authentication context. -
To test the API Instance with authentication, replace the public endpoint placeholder and run this command in the terminal window:
curl -s -o /dev/null -w "%{http_code}\n" --request GET '<publicEndpoint>' -u user:password
sshThe user
andpassword
parameters must match what was specified when you applied the policy via API Manager.The command prints the resulting
200
status code, indicating success.