How to: Rest endpoint returning empty object

Found the solution: By casting the return value to an object, it is ensured that in case of an empty array, an empty object will be returned on REST request.

Enhancing on my initial example, this code would work:

function rest_cb() {
    return (object) array();
}

Leave a Comment