I am creating a simple soothing api using zend framework2 and I have links to Rob Allen's notes on this subject, as well as this excellent tutorial from http://hounddog.github.com/blog/getting-started-with- rest-and -Send-frame 2 /
below is my mod_config.php. You will see that I have routes and the JSON viewing strategy is configured. I understand that when setting up a JSON strategy in this way, it supports all modules. The problem is that if you enter the wrong route, the 404 response is sent back to html, even if the Accept header asks for Application / json.
I struggled with this for 2 days, whenever we advised or helped
This curl call for api generates the expected 404 error.
curl -i -H "Accept: application/json" http:
Module_config.php
return array( 'controllers' => array( 'invokables' => array( 'Dips\Controller\Roles' => 'Dips\Controller\RolesController', //maps controller alias to a physical controller ), ), 'router' => array( 'routes' => array( 'dips' => array( 'type' => 'segment', 'options' => array( 'route' => '/dips/roles/:apikey/:uname/:appname', 'constraints' => array( 'apikey' => '[a-zA-Z0-9]+', 'uname' => '[a-zA-Z]+', 'appname' => '[a-zA-Z][a-zA-Z0-9_-]*', ), 'defaults' => array( 'controller' => 'Dips/Controller/Roles', ), ), ), ), ), 'view_manager' => array( 'strategies' => array( 'ViewJsonStrategy', ), ), );
source share