Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create action based on resource in zend apigility like — /users/[/:user_id]/customAction #8

Open
weierophinney opened this issue Dec 31, 2019 · 5 comments

Comments

@weierophinney
Copy link
Contributor

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.


Originally posted by @sarathbabuSwamynathan at zfcampus/zf-apigility#187

@weierophinney
Copy link
Contributor Author

@sarathbabuSwamynathan I may be way off base here since it doesn't answer your question directly, but I would create another service for resetting password operations for simplicity. I would then change the route from the default to be /users/reset_password[/:user_id]


Originally posted by @sariabod at zfcampus/zf-apigility#187 (comment)

@weierophinney
Copy link
Contributor Author

Thanks for your reply Sam. I thought of creating apis like which i have seen following link

campaign

http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/#%20

Multiple actions are there. If its is created in single rest api, then it will be easy to maintain it and it will removes some confusions down the road.


Originally posted by @sarathbabuSwamynathan at zfcampus/zf-apigility#187 (comment)

@weierophinney
Copy link
Contributor Author

It is quite common to use an RPC (remote procedure call) solution for such things like resetting a password. You could also treat the password as a resource and allow PUT-ting it, but you would have to come up with your own model for this. Using an RPC solution will probably be the easier way to go.

Check here for docs on the zf-rpc module: https://apigility.org/documentation/modules/zf-rpc

Check also this post on stackoverflow that might be interesting for you: http://stackoverflow.com/q/3077229/1697459


Originally posted by @Wilt at zfcampus/zf-apigility#187 (comment)

@weierophinney
Copy link
Contributor Author

Thanks Sam and Wlit for your earliest reply.


Originally posted by @sarathbabuSwamynathan at zfcampus/zf-apigility#187 (comment)

@weierophinney
Copy link
Contributor Author

Hi @sarathbabuSwamynathan ,

creating a service under users is as far as I've seen just a matter of properly routing.
Start by creating a new Rest API service for example with the admin tool, then set the route in your corresponding module.config.php file. i.e under the router.routes configuration key have something like this:

'router' => [
    'routes' => [
        'your_module_name.rest.custom_stuffs' => [
            'type' => 'Segment',
            'options' => [
                'route' => '/users/:user_id/custom_stuffs[/][:custom_stuff_id[/]]',
                'defaults' => [
                    'controller' => 'Wallet\\V1\\Rest\\CustomStuffs\\Controller',
                ],
            ],
        ],
    ],
],

that should be it


Originally posted by @Nguimjeu at zfcampus/zf-apigility#187 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant