user15592843
user15592843

Reputation: 15

How to call a rest api from within the mule proxy

How to call a rest api from within the mule proxy

Clients -> Mulesoft proxy (I need to call a Rest service A , here to authenticate a client ) -> if authentication passes then call actual REST service B.

Upvotes: 0

Views: 1135

Answers (2)

Rohan
Rohan

Reputation: 637

This is how you can create a mule app to call a backend service if authenticated properly.

 Client -> Mule App A(apply API manager policies) -> if authenticated call service B
  1. Build a Mule app A to call backend service B in the eclipse studio.
  2. Go to API manager in Anypoint platform and Create a new API. You can provide a name and the asset type could be HTTP
  3. Managing type : Basic endpoint. Don't mention implementation URL. Save
  4. Once you click save, you'll get a API ID displayed on the screen which will be a unique number. You now have to tie this API ID to the Mule app A built in step 1.
  5. Go back to your Mule app A and configure a global element called API Auto discovery. Mention the API ID here and choose the flow name.
  6. Deploy your Mule app A and you'll see that after successful deployment the App A will connect with your Mule organization's API ID(provided you have the organization's anypoint client id/secret from access management in anypoint platform correctly configured).
  7. Now, go back to API manager and verify for the API ID that the API status has become Active.
  8. Apply any API security policy in API manager and it should get applied on the Mule App A.

Some additional info: Typically, you would have a DMZ or an edge zone where you would deploy your gateway components through which traffic would flow into your enterprise and hit various applications. One such internal application could be Mule app A developed to call your backend REST service B. Now, to protect your developed Mule app API endpoint with security API policies you could use API manager. Once you do this within API manager by selecting all the relevant policies such as client credentials, Oauth jwt validation or rate limit etc, the anypoint platform spins up a Mule app which with all these policies embedded in the app(also known as the proxy app) and will ask you to point to a backend API which would be the Mule app A that you previously developed. You also have to select a runtime to run this Mule proxy app which typically be in your edge runtime environment/zone. Basically, the anypoint platform creates this app for you and does the embeds the required code/policies etc. Now if required you can edit this app as well which I wouldn't recommend.

  Clients -> Mule proxy app(Security policies applied) -> Mule app A -> REST service B

Upvotes: 0

aled
aled

Reputation: 25699

An API proxy in Anypoint Platform is implemented as a Mule application to which policies are applied. You have to download the proxy, import it into Anypoint Studio and edit it to add the HTTP request to service A, then continue as before. If the authentication fails with an HTTP response status >= 400 you probably don't need to do anything special, unless you need to customize the HTTP request error status check or customize the response status.

Upvotes: 1

Related Questions