how to configure mockoon endpoint with queryParam?

I have a get in mockoon with the path /search/data (which is the path in RestClient too) and in RestClient it also sends a queryParam (@QueryParam("dataCode") String dataCode);

How do I configure mockoon to work with the application call (it's java with quarkus).

In the route I just put /search/data. The documentation said not to put any queryParam in the route, but I couldn't understand where to configure it and how in mockoon for this to work. Apart from the port and the route, the only config I put in was a response body that I wanted to return.

I would appreciate if anyone has a better example of how to do this, the documentation was not clear to me.

documentation link

https://mockoon.com/docs/latest/templating/mockoon-request-helpers/#queryparam

Upvotes: 0

Views: 2239

Answers (1)

255kb - Mockoon
255kb - Mockoon

Reputation: 6974

Query parameters are not part of the endpoint declaration. To use query parameters, just call your endpoint with them, like this: /search/data?dataCode=value

It will be automatically parsed by Mockoon (relevant documentation: https://mockoon.com/docs/latest/api-endpoints/routing/#query-parameters). You can pass strings, arrays and objects.

After, you can use the query parameters in a template using the helpers you linked to:

{{queryParam 'dataCode'}}

Or you can use them in rules, to return a 400 when the parameter is missing, and a 200 when the parameter is present, for example. You will find a tutorial on rules here (example is with a header, but it's ot complicated to transpose to a query parameter).

Upvotes: 0

Related Questions