Dynamic call in RAML based on query params

671 views Asked by At

Need help on dynamic call in query parameter in RAML.

In RAML, I want to call .raml files which are in Examples folder dynamically. Through query param, if I send ?count=2 (example: https://anypointpoint.mulesoft.com/mocking/api?count=2) then 2_records.raml file to execute in response which is in Examples folder... If I send ?count=3 then 3_records.raml file to execute in response which is in Examples folder.

api specification as below to understand clearly :

/retrieveDetails get: queryParameters: count: #if query param ?count=2(in mock url) then 2_records.raml to execute. If query param ?count=3 (in mock url) then 3_records.raml to execute. enter image description here type: string responses: 200: body: application/json example: !include Examples/2_records.raml

And attached screenshot as well to understand easily.

1

There are 1 answers

2
aled On

RAML files are not executable and are not meant to be dynamically 'called' or 'requested'. Rather they describe the structure and types of an API. They may include optionally examples, but there is no way to 'select' one example over others.

I think your question is really related to how the Mocking Service in Anypoint Platform works. This is a product that uses the RAML files to simulate API requests. Reading the documentation I don't see a way to select a specific example at all.

As an alternative you could implement the API in an application and add the logic to return the desired response based on the query parameters inputs. For example you can use APIKit to scaffold the RAML API in Anypoint Studio and deploy/execute in a Mule runtime.