Hi, I’m quite the newbie in Mendix, and I have a problem and a hard time solving it. I have created a published REST service that queries a database, retrieves a list based on a parameter, and returns it. The entire API works, but I got stuck trying to implement a filter. There’s a query parameter that can be provided with the GET call. This parameter is in an XPath query in my Retrieve from Database action. I got the filter to retrieve based on the parameter, but I want an ‘GET ALL’ function, where it completely disregards that specific XPath filter. So currently, my filters look like this: [vehicle=$vehicle] [status=$status] I can retrieve specific statuses when providing it as a parameter in my GET call. I have also set it to a default value in case it’s not provided. However, what I can’t seem to figure out, is how to retrieve ALL events for a vehicle, so leaving out the [status=$status] when the parameter ‘status=all’ is provided in the GET call. Any pointers would be great, I’m here to learn!
You could add a split before the retrieve action where you check if the status=all parameter is provided.
If that results in true do the database retrieve without including a specific status in your xpath. In the false path you'd still use the database retrieve action as you currently have it moddeled.
This also improves the readability of the microflow thats executed by the rest service, as opposed to working with just one retireve action which has a complicated xpath statement.
You could also work with the following Xpath in your current retrieve:
[$status = empty or status=$status]
Of course that would imply that the request does not contain the parameter status if someone doesn't want to filter on status.