Mule ApiKit - Endpoints for ../api/items and ../api/items/{itemId} at the same time?

112 Views Asked by At

In mule how can we serve endpoints for ../api/items and ../api/items/{itemId} at the same time ?

I was wondering how to make the ApiKit work for the endpoints.. I get nullpayload and an exeption when I call ../api/items which was exactly defined in https://support.mulesoft.com/s/article/ka434000000TPOz/Method-not-Allowed-on-API-Kit-requests

But there the solution mentioned is not practically applicable

2

There are 2 best solutions below

0
On BEST ANSWER

I resolved it just adding a groovy script before APIkit Router .

It is

import org.mule.api.transport.PropertyScope

if(message.getInboundProperty('http.request.path') == '/api/items') 
    message.setProperty('http.request.path', '/api/items/*', PropertyScope.INBOUND)`

And when I see a star * as the item id I behave accordingly in the flow implementation

1
On

In raml both of this endpoint are valid. You can use this there is no problem for that.