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.

 

Diagram Description automatically generated

 

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

Graphical user interface, application Description automatically generated with medium confidence

 

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

 

Graphical user interface, application, Teams Description automatically generated

Installing Flex Gateway in Docker Container

 

  • Install Docker
    1. Download and install “Docker Desktop” in your system if not installed. You can use existing docker environment also
  • Download image
    1. Download the “Flex Gateway Docker Image” using the below command

docker pull mulesoft/flex-gateway:1.0.0

  • Register
    1. register the Flex Gateway to Anypoint platform by running the following command in docker. Note – replace <gateway-name> with your own value.
    2. 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
    3. After successful executed the above command, you could see your Flex Gateway in Runtime Manager inside Flex Gateway option.
    4. You should also see 3 following files generated where you have executed your command.
      1. 6eb12385-c2f0-4546-b574-8a030a321d74.conf
      2. 6eb12385-c2f0-4e03-b574-8a030a321d74.key
      3. 6eb12385-c2f0-4e06-b574-71030a321d74.pem
    5. Save the path and the UID for later use.
  • Run Flex Gateway
    1. 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
    1. Check the status of Flex Gateway from Anypoint platform.

Graphical user interface, text, application Description automatically generated

Configure API in Flex gateway using API manager

 

  • Go to API manager and add new API. Select Flex Gateway as runtime.

Graphical user interface, text, application Description automatically generated

 

  • Select the Flex Gateway created earlier

Graphical user interface, text, application Description automatically generated

 

  • Select API from exchange or create a new one

Graphical user interface, text, application Description automatically generated

 

  • 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.

Graphical user interface, text, application, email Description automatically generated

 

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.

Graphical user interface, text, application, email Description automatically generated

 

  • Review the provided information and deploy the API in Flex Gateway.

Graphical user interface, text, application, email Description automatically generated

Configure Policies in Flex gateway using API manager

 

Apply “Basic Authentication” policy to the API from API manager as shown below

Graphical user interface, text, application, email Description automatically generated

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

 

Graphical user interface, text, application, email Description automatically generated

 

Success response after correct authentication.

Graphical user interface, text, application, email Description automatically generated

Docker Logs

You can check docker logs to know about any changes to API configurations.

Graphical user interface, text, application, email Description automatically generated

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:

Bappi Modak
Associate Technical Architect at Tavant Technologies
LinkedIn Profile
  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Bappi
Bappi
1 month ago

Thanks Pawan for your guidance and support to complete this article.

Abhishek
Abhishek
1 month ago

Is it all possible in mulesoft trail account?

Zakir
Zakir
1 month ago

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 »

Zakir
Zakir
1 month ago

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?