DZone
Integration Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Integration Zone > How to Invoke a REST API

How to Invoke a REST API

Look at how to invoke a REST API.

Vishal Mujumdar user avatar by
Vishal Mujumdar
·
Aug. 02, 19 · Integration Zone · Code Snippet
Like (3)
Save
Tweet
21.76K Views

Join the DZone community and get the full member experience.

Join For Free

Problem Statement

Recently, while working with MuleSoft 4 (AnyPoint Platform - 7.3.1), I had come across a scenario that requires the invocation of another REST API, which is also implemented on MuleSoft. This API requires input in the form of URI parameters. This API works well when invoked from an external client like Postman, however, exceptions are observed when the same API is invoked from MuleSoft.

Implementation Details

App - Currency Conversation is implemented for providing currency conversion details in real-time, and this APP can be invoked by URL  -http://<<hostname>> /api/ currenyconversion /baseCcy /<<value>> /targetCcy/<<value>>

E.g - http://localhost:8081/api/currenyconversion/baseCcy/USD/targetCcy/INR

Observations

  1. Sucessfile response is observed when this API is invoked by clients like Postman etc., however, when this scenario is invoked from MuleSoft, i.e a MuleSoft flow that invokes this particular API, exceptions were observed.

  2. After further debugging, it was found that when this API was invoked with Postman, rawRequestPath of API is found to be of type "/api/currenyconversion /baseCcy /NZD/targetCcy/INR", which clearly describes on input parameters that require transformation. 

  3. When this API is invoked from another Mule app, the raw request Path of the API is found to be of type  "/api/currenyconversion". In this case, input parameters are found to be missing that are required for data processing.

Code Snippet of HTTP requestor configuration that invokes API

<http:request method="GET" doc:name="Request" doc:id="c0c65c9a-8263-4442-a250-6922531925c2" path="#['/currenyconversion/']" sendCorrelationId="ALWAYS" config-ref="invesco-httpRequestor-processApi"> <http:uri-params > <![CDATA[#[output application/java --- { baseCcy : vars.queryVarBaseCcy, targetCcy : vars.queryVarTargetCcy }]]]> </http:uri-params> </http:request>

Troubleshooting and Workaround

There seems to be some technical glitch due to the URI parameters not getting appended to the request URL. So, a workaround is required to append URI Parameters to the path.

<http:request method="GET" doc:name="Request" doc:id="c0c65c9a-8263-4442-a250-6922531925c2" sendCorrelationId="ALWAYS" config-ref="invesco-httpRequestor-processApi" path="#['/currenyconversion/baseCcy/' ++ vars.queryVarBaseCcy ++ '/targetCcy/'++ vars.queryVarTargetCcy]"> </http:request>

Thank you!

API REST Web Protocols MuleSoft

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 5 Options for Deploying Microservices
  • The Digital Finance Revolution, Open Banking, and APIs
  • The Best Solution to Burnout We’ve Ever Heard
  • Create a Millisecond-Precision Time Ticks Chart with NodeJS

Comments

Integration Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo