Skip to content

[Question] Multiple identifiers in route #3064

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
mxkh opened this issue Sep 11, 2019 · 7 comments
Closed

[Question] Multiple identifiers in route #3064

mxkh opened this issue Sep 11, 2019 · 7 comments

Comments

@mxkh
Copy link

mxkh commented Sep 11, 2019

Hello folks!

How I can configure route with multiple identifiers? For example:

[PUT] /api/user/{user_id}/post/{post_id}

Some examples you can find here https://symfony.com/doc/master/bundles/FOSRestBundle/6-automatic-route-generation_multiple-restful-controllers.html#define-child-resource-controller

Does this option supported by API Platform?

@jamesisaac
Copy link
Contributor

That would be Subresources: https://api-platform.com/docs/core/operations/#subresources

Although it sounds like they're only supported for GET operations at the moment.

@mxkh
Copy link
Author

mxkh commented Sep 11, 2019

That would be Subresources: https://api-platform.com/docs/core/operations/#subresources

Although it sounds like they're only supported for GET operations at the moment.

@jamesisaac Thank you for your response

Yes, I know. I saw it in the documentation and I already found a related topics
api-platform/api-platform#947
#1628

But I really don't understand why it's not implemented, I think it's a basic concept for the REST (https://restfulapi.net/rest-api-design-tutorial-with-example/#model-uris), maybe I am wrong and there is exist another way how to handle but I feel that it's not

#1628 (comment)

@dunglas So, If there is exist another "right" way how to PUT\DELETE subresource just direct me :)

@soyuka
Copy link
Member

soyuka commented Sep 13, 2019

Hi, just use a custom operation with your custom controller like you'd do with a normal symfony application it'll work.

@ziiko10
Copy link

ziiko10 commented Nov 25, 2019

@soyuka Yes but when you use a custom operation you can only specify the identifier of the current entity, you cannot do something like this :

    *          "ADD-CATEGORY-TO-PRODUCT"={
    *              "method"="POST",
    *              "path"="/products/{id}/categories/{categoryId}",
    *              "controller"="App\Controller\AddCategoryToProductController"
    *          }

Because {categoryId} is unknown .

Any solution please ?

@soyuka
Copy link
Member

soyuka commented Nov 25, 2019

Don't specify the path like this but instead just specify a route_name. Then, declare the route via symfony with your favorite way (Route annotation or yaml/xml). I think it'll work.

@Rebolon
Copy link

Rebolon commented Feb 18, 2020

I thought that Custom Operation wasn't a good practice ?

For Post operation, if you use a DataPersister, the crash will happen after the persist method, when ApiPlatform try to generate the IRI for the related resource IriConverter::getItemIriFromResourceClass

I didn't find any solution for this whereas we should only need to decorate the iriConverter, then the parameters identifiers would provide all required route parameters. But how to specify a decorated IriConverter only for a specific route ? Maybe it's overkill ?

@soyuka
Copy link
Member

soyuka commented Feb 18, 2020

I'm sorry @Rebolon not sure to follow, please open a new issue as it's not really related? You can decorate the IriConverter to support multiple identifiers indeed.

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

5 participants