We are setting a Rest API in a ZF1 web app and we're having trouble configuring the routes.
The idea is to have a global configuration in the application.ini that includes the 'classical' Rest routes and optional actions.
That means that we want to have the basic CRUD operations like this :
GET /user/1
POST /user
PUT /user/1
DELETE /user/1
But also custom actions like :
GET /user/findBySomething
For now the routes of our app are defined in the application.ini like this :
resources.router.routes.app.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.app.route = ":module.myApp.com"
resources.router.routes.app.defaults.module = "app"
resources.router.routes.app.chains.default.type = "Zend_Controller_Router_Route"
resources.router.routes.app.chains.default.route = ":lang/:@controller/:@action/*"
resources.router.routes.app.chains.default.defaults.lang = "fr"
resources.router.routes.app.chains.default.defaults.controller = "index"
resources.router.routes.app.chains.default.defaults.action = "index"
We want a different configuration for our api, so far we have this :
resources.router.routes.api.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.api.route = ":module.myApp.com"
resources.router.routes.api.defaults.module = "api"
resources.router.routes.api.chains.default.type = "Zend_Controller_Router_Route"
resources.router.routes.api.chains.default.route = ":lang/:@controller/*"
resources.router.routes.api.chains.default.defaults.lang = "fr"
resources.router.routes.api.chains.default.defaults.controller = "index"
resources.router.routes.api.chains.default.defaults.action = "index"
And we catch the request in an abstract API controller and define which method to call depending on the HTTP method of the request.
This works well for the basic CRUD operations but logically won't work yet if we want to access a custom action, and we can't figure out a way to do this.
We've unsuccessfully tried several options like using a Zend_Controller_Router_Route_Regex
to define the routes; or adding manually the custom routes with addRoute()
in the Bootstrap.
Does anyone have an idea? After the time we spent in research, so far it looks like ZF1 can't allow us to set up a proper Rest API...