REST return single object when parameter is given, not array with one object

1
Hi everyone, We have a published REST service that returns JSON for a request.   The following goes well: - https://localhost:8080/rest/getOrders Returns a list of all orders. https://localhost:8080/rest/getOrders Returns a single order with id = 1234   The one thing that I can't get to work properly is this: - https://localhost:8080/rest/getOrders?description=abc The microflow from getOrders is triggered (resulting in a list of objects) and based on the parameter an array with just a single object is returned. This is not the desired functionality, I want to have a single object returned so that the resulting JSON is correct and not an array. I've tried figuring this out with the REST Services module and the native REST service available in Mendix 7.13, but so far: no dice. Hopefully someone can show me what I have been overlooking or perhaps the desired result isn't possible at all? Thanks in advance!
asked
3 answers
2

You are talking about one operation that returns a different structure based on whether you specify the query parameter 'description' or not. That makes it difficult for clients to interpret the response, so that's not how you would want to design it.

I would suggest making two operations, and calling the second one https://localhost:8080/rest/getOrder (singular), to indicate that it returns only one object. The microflow for that operation returns a single object.

answered
0

Can you share the REST/JSON standards that your integration partner is using? I feel pretty strongly that a single-item array makes more sense in the case where there is only one search result vs. just returning an object.

answered
0

Do you use the same JSON structure in those 2 requests?

Because if it is defined as an array, then you will always retrieve an array.

answered