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
- 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.
- 6eb12385-c2f0-4546-b574-8a030a321d74.conf
- 6eb12385-c2f0-4e03-b574-8a030a321d74.key
- 6eb12385-c2f0-4e06-b574-71030a321d74.pem
- 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.
Docker Logs
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.
References
You can go through with the references below from MuleSoft to understand more.
https://blogs.mulesoft.com/news/anypoint-flex-gateway/
https://docs.mulesoft.com/gateway/flex-gateway-overview
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:
|
Thanks Pawan for your guidance and support to complete this article.
Is it all possible in mulesoft trail account?
Yes, it is possible in developer account!
Hello, the point that is saying – Provide the API endpoint and click next. We need to provide the implementation URL as Flex gateway will forward the API request to the implementation URL. where we are and just after this, it is mentioned that – Our actual API is running on cloud hub with endpoint http://flex-demo-dev.us.e2.cloudhub.io/api/v1/ . You can use the endpoint of any API running in your organization in any tech stack. so my question is can we ignore this point “Select API from the exchange or create a new one” , here is It really required to create… Read more »
it is really confusing that the new API gateway offers to manage and secure APIs running anywhere (cloud, on-premise) in any tech stack (java, .net, python, etc).
if my api is writen in JAVA and have an endpoint so do we reaally need to register it on exchnage to give it in API section of flex gateway?
bu how we will publish it on exchange it is java API?
You would need to register it in Exchange first to manage an API. You just need to add it as HTTP API if you don’t have RAML or Swagger documentation of your API.
As in the image
We have some legacy SOAP apis that we have in our product that we’d like to setup in the API Flex Gateway. AWS Gateway has a method for doing this but I don’t see one for the MS API Flex gateway. How can we accomplish this without having to re-code our application to use Rest?