Leveraging API dispatches from RPC in Apigility

By December 16, 2013 September 5th, 2019 No Comments

Apigility provides a good resource-based API but when you need more data than a resource provides it’s time for custom RPC dispatches.

Apigility RPC provides a controller which returns an array which is transformed to JSON.

To call an API controller then modify its response you need to dispatch the controller from the RPC controller, render the HalJson resonse, then decode it back to an array.

        $hal = $this->forward()->dispatch($controller, array(
            'id' => 1,
        $renderer = $this->getServiceLocator()->get('ZFHalJsonRenderer');
        $data = json_decode($renderer->render($hal), true);

Having ran this example your $data will be an array of the rendered HalJson. You can modify it and return the modified array from the RPC controller.


        $data['moredata'] = array('more', 'data');

        return $data;

Leave a Reply

Need to adjust your business processes quickly? We're helping clients use technology to keep their teams productive and running smoothly in these times of uncertainty. Our team can guide yours if you need help in these areas.

Talk to a Consultant