Contact Us 1-800-596-4880

Getting Started with Flex Gateway

The goal of this tutorial is to quickly get started with Anypoint Flex Gateway. Using Docker, the tutorial describes how to install, register, and run Flex Gateway in Connected Mode. 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:

  • A username and password for your Anypoint Platform organization. If you don’t have Anypoint Platform yet, create a Trial organization on Anypoint Platform.

  • A Linux machine with an x86 processor. M1 and M2 processors are not supported.

    Flex Gateway runs on the following Long Term Support (LTS) versions of Linux:

    • Amazon Linux 2

    • CentOS 8

    • Debian (Buster, Bullseye, and Bookworm starting with Flex Gateway 1.6.2)

    • Red Hat Enterprise Linux (8, 9)

    • Ubuntu (Bionic, Focal, Jammy)

  • A Docker installation. See Docker Desktop for an example.

Download Flex Gateway

To download the Flex Gateway Docker image, run the following command in a terminal window:

docker pull mulesoft/flex-gateway:latest
Use sudo if you encounter file permission issues when running this command.

Register Flex Gateway

  1. Create a new directory by running:

    mkdir flex-registration
  2. Navigate to the new directory by running:

    cd flex-registration
  3. Log in to Anypoint Platform with your Anypoint username and password.

  4. Select Runtime Manager.

  5. Click on the Flex Gateways tab in the side navigation panel.

  6. Click Add Gateway.

  7. Select Docker.

  8. Copy the code block in the Register your gateway section. The code block contains your unique organization ID and token.

    The following screenshot of the Add a Flex Gateway page highlights the code block to copy:

    Add a Flex Gateway page with code block to copy selected
  9. Run the copied code block in your terminal window, making sure to first replace <gateway-name> with a name, such as my-gw.

    Use sudo if you encounter file permission issues when running this command.
  10. In Runtime Manager, select Flex Gateways from the side navigation panel.

    Your registered Flex Gateway now appears in the list of gateways.

Run Flex Gateway

To run Flex Gateway, run the following in a terminal window:

docker run --rm \
  -v "$(pwd)":/usr/local/share/mulesoft/flex-gateway/conf.d \
  -p 8081:8081 \
  mulesoft/flex-gateway
Use sudo if you encounter file permission issues when running this command.

A new Flex Gateway instance is now running in your terminal window.

The Flex Gateway instance will continue running in the terminal window until the process is stopped, or until the window is closed.

Publish a Simple API

  1. Select API Manager from the Anypoint Platform menu.

  2. Click Add API, followed by Add new API:

    Add new API page with Add new API selected
  3. From the Add API page, select Flex Gateway as your runtime.

  4. Select your registered gateway in the Select a gateway section.

  5. Click Next.

    The following screenshot of the Add API page highlights the specified options:

    Add API page with Flex Gateway Runtime and my-gw gateway selected
  6. Click Create New API.

  7. Specify an API name and select HTTP API as the asset type.

  8. Click Next.

  9. From the Endpoint page, enter the following in the Implementation URI field:

    https://jsonplaceholder.typicode.com/
  10. Enter 8081 in the Port field.

  11. Click Next.

  12. Click Save & Deploy.

    Inside the gateway instance Docker container, all HTTP requests made to localhost on port 8081 are now proxied to the jsonplaceholder service.

  13. To test the API Instance, run the following command in a new terminal window:

    curl -s -o /dev/null -w "%{http_code}\n" --request GET 'http://localhost:8081/'

    The command executes a GET request to the API, and then prints the resulting 200 status code, indicating success.

Secure Your API Using the Basic Authentication Policy

  1. While still in API Manager, select API Administration from the side navigation panel.

  2. Select the name of the API created in the previous section.

  3. Select Policies from the side navigation panel.

  4. In the Policies page, click Add policy.

    The following screenshot of the Policies page highlights the specified options:

    Add Policy page with Add policy button
  5. Select the Basic Authentication - Simple policy.

  6. Click Next.

  7. For User Name, enter user.

  8. For User Password, enter password.

  9. Click Apply.

    The following screenshot of the Configure Basic Authentication - Simple policy page highlights the specified options:

    Configure Basic Authentication Policy page with User Password field selected
  10. To test the API Instance without authentication, run the following curl command in the terminal window:

    curl -s -o /dev/null -w "%{http_code}\n" --request GET 'http://localhost:8081/'

    The command prints a resulting 401 (Unauthorized) status code, because the request does not include the Authentication context.

  11. To test the API Instance with authentication, run the following command in the terminal window:

    curl -s -o /dev/null -w "%{http_code}\n" --request GET 'http://localhost:8081/' -u user:password
    The user and password parameters must match what was specified when you applied the policy via API Manager.

    The command prints the resulting 200 status code, indicating success.