Skip to content

Allow other operation than GET for sub resources #2251

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

Closed
soullivaneuh opened this issue Oct 11, 2018 · 6 comments
Closed

Allow other operation than GET for sub resources #2251

soullivaneuh opened this issue Oct 11, 2018 · 6 comments

Comments

@soullivaneuh
Copy link
Contributor

As described in the documentation:

Since ApiPlatform 2.1, you can declare subresources (only for GET operation at the moment).

At the moment mean it will change, right? 😜

So, here is something planned about it? Do you think it's something easy to do?

Regards

@soyuka
Copy link
Member

soyuka commented Oct 11, 2018

Wouldn't be that hard but definitely requires work.

POST /dummy/1/relatedDummy

Would expect a RelatedDummy and will have to set the reverse relation on dummy/1 to this new one. I think that it should work without much additions if Doctrine can persist the owner from the opposite side?

Anyway, for now I'd advise you to build a custom operation with a DataPersister handling your specific use case.

@soullivaneuh
Copy link
Contributor Author

Anyway, for now I'd advise you to build a custom operation with a DataPersister handling your specific use case.

Would you please like to elaborate? With a sample or a link? Thanks.

@soyuka
Copy link
Member

soyuka commented Oct 11, 2018

Something like:

<?php
/**
 * @ApiResource(
 *     itemOperation={
 *          "answer_post"= {
 *              "method"="POST",
 *              "path"="/question/{id}/answer
 *          }
 *      }
 * )
 */

Then https://api-platform.com/docs/core/data-persisters/#creating-a-custom-data-persister (you can use the Request with the attribute given by $request->attributes->get('_api_item_operation_name') in the support method to check that you call this operation only when the operation name is answer_post)

@soullivaneuh
Copy link
Contributor Author

Thank you @soyuka, I'll give a try. 😉

@torreytsui
Copy link

Hello @soyuka, @soullivaneuh, is there any update?

I'm checking and see if I can help implementing this. It will be a great feature for the project I'm working on as we have many real use cases for it. Let me know 😃

@soyuka
Copy link
Member

soyuka commented Feb 19, 2021

closing will be supported in 3.0

@soyuka soyuka closed this as completed Feb 19, 2021
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

3 participants