MuleSoft Anypoint Flex Gateway
Anypoint Flex Gateway is MuleSoft’s new API gateway offering to manage and secure APIs running anywhere (cloud, on premise) in any tech stack (java, .net, python, etc).
With the new Anypoint flex gateway, Organizations will be able to manage and govern all the APIs under one roof.
MuleSoft Anypoint Platform now offers 3 API gateway options for managing backend APIs. You can refer to MuleSoft docs for more detail https://docs.mulesoft.com/gateway/flex-gateway-overview
- Flex Gateway
- Mule Gateway
- Anypoint Service Mesh
In this tutorial we will talk about Anypoint Flex gateway only.
Getting started with Flex Gateway
Running Flex Gateway
Anypoint Flex Gateway can be run in two ways. We will be using the connected mode for this tutorial.
- Connected Mode – In this mode API management is done using Anypoint control plane.
- Local Mode – API Management is done locally using stored configuration files.
Installing Flex Gateway
Anypoint Flex Gateway can be installed using options below. Here we have demonstrated how to run it as docker container. The scripts get generated automatically as you select the option.
- Install as a Linux service
- Install in a docker container
- Install as a Kubernetes ingress controller
Installing Flex Gateway in Docker Container
- Install Docker
- Download and install “Docker Desktop” in your system if not installed. You can use existing docker environment also
- Download image
- Download the “Flex Gateway Docker Image” using the below command
docker pull mulesoft/flex-gateway:1.0.0
- register the Flex Gateway to Anypoint platform by running the following command in docker. Note – replace <gateway-name> with your own value.
- docker run –entrypoint flexctl -w /registration \ -v “$(pwd)”:/registration mulesoft/flex-gateway:1.0.0 \ register <gateway-name> \ –token=3011160f-a9cb-4392-ae78-55d3f9c1655a \ –organization=34010c23-aeab-4d96-908e-8eb123b48ce5 \ –connected=true
- After successful executed the above command, you could see your Flex Gateway in Runtime Manager inside Flex Gateway option.
- You should also see 3 following files generated where you have executed your command.
- Save the path and the UID for later use.
- Run Flex Gateway
- execute the following command in docker.
Note – Put the absolute path where you have generated the conf file.
docker run –rm \ -v <absolute-path-to-directory-with-conf-file>/:/etc/flex-gateway/rtm \ -p 8081:8081 \ -e FLEX_RTM_ARM_AGENT_CONFIG=/etc/flex-gateway/rtm/<UUID-of-your-file>.conf \ mulesoft/flex-gateway:1.0.0
- Check Status
- Check the status of Flex Gateway from Anypoint platform.
Configure API in Flex gateway using API manager
- Go to API manager and add new API. Select Flex Gateway as runtime.
- Select the Flex Gateway created earlier
- Select API from exchange or create a new one
- Provide the API endpoint and click next. We need to provide the implementation URL as Flex gateway will forward the API request to implementation URL.
Our actual API is running on cloudhub with endpoint http://flex-demo-dev.us.e2.cloudhub.io/api/v1/ . You can use end point of any API running in your organization in any tech stack.
- Review the provided information and deploy the API in Flex Gateway.
Configure Policies in Flex gateway using API manager
Apply “Basic Authentication” policy to the API from API manager as shown below
Testing the API deployed in Flex gateway using Postman
FYI, our flex gateway is running in local machine as container with port 8081.
Sending request without authentication failed as expected
Success response after correct authentication.
You can check docker logs to know about any changes to API configurations.
Points to Note
- Endpoint (Implementation) URL: Provide URL till base path only, and not the complete end point including resource name.
- Flex Gateway deployed in Docker runs on the specified port (eg 8081), so all the API request goes via 8081, Gateway will apply the policies.
You can go through with the references below from MuleSoft to understand more.
This was all about Anypoint Flex gateway. Please do let us know if you face any issue in setting up flex gateway. Happy reading!
Post Submitted by: