Reputation: 1
I am using apigility 1.4.1 to create my rest api services.
In my case this is my routing url /users/[/:user_id]
and when i give user id with GET Http method it gives me that one particular user details.
and when i need all user details then i suppose to give /users with HTTP GET method
If it is user creation, then I will give /users and user details in request body with HTTP POST Method.
Above all are working fine for me, because apigility created routing and resource classes to receive request based on HTTP methods.
For example, If it is GET method with single entity it will route it to fetch method present in Resource class. If it is POST method with request body data then it route it to create method in Resource class.
But,
When I need to create routing url like users/[/:user_id]/reset_password
I don't know how to create it with my zend apigility rest api creator and where to receive that request and where to create my own controller to receive the request.
Can anyone please help me to do this. Thanks in advance.
Upvotes: 0
Views: 232
Reputation: 21
In this case you should do a RPC. Here is a configuration example:
return array(
'controllers' => array(
'invokables' => array(
'MyNameSpace\UserController' => 'MyNameSpace\UserController',
),
),
'router' => array(
'routes' => array(
'user' => array(
//Your REST route
),
'user-reset-password' => array(
'type' => 'Segment',
'options' => array(
'route' => '/user/:user_id/reset-password',
'defaults' => array(
'controller' => 'MyNameSpace\UserController',
'action' => 'reset-password',
),
),
),
),
),
'zf-rpc' => array(
'MyNameSpace\UserController' => array(
'http_methods' => array('POST'),
'route_name' => 'user-reset-password',
),
),
'zf-rest' => array(
//Your REST config
)
);
And then you must create the UserController for your RPC:
namespace MyNamespace;
use Zend\Mvc\Controller\AbstractActionController;
class UserController extends AbstractActionController
{
public function resetPasswordAction()
{
//Your action
}
}
For more information read the docs
Upvotes: 1