Core: How to change Subresource path

Created on 6 Nov 2017  路  7Comments  路  Source: api-platform/core

Is it possible to change the path of a subresource?

bug

Most helpful comment

answer_get_subresource is the operation name

All 7 comments

It should work just as you would overwrite the one of a collection operation.

For example:

# src/AppBundle/Resources/config/api_resources/resources.yml
AppBundle\Entity\Answer:
    collectionOperations:
        api_questions_answer_get_subresource:
            method: 'GET' # nothing more to add if we want to keep the default controller
            path: '/foo/{id}/bar'

Before you do this check debug:router to get the operation name and the identifier names (they'll have to stay the same).

docs

When I am naming my collectionOperation to api_teams_users_get_subresource then it will be called api_teams_api_teams_users_get_subresource_collection in the router.

Mhh I need to change the docs on this it艣 s actually only the suffix. Just like you're doing to replace a collection operation (ie get, put) here it's property_get_subresource:

For example to replace the api_users_person_get_subresource_collection path I did:

        collectionOperations:
            person_get_subresource:
                method: 'GET'
                path: '/foo/{id}/bar'

The problem is that i don't want to change the api_users_person_get_subresource_collection.
I want change the api_users_person_get_subresource and that's unfortunaley not possible at all :(

Okaaayy. My bad thought this was fine!

So, the correct way was your first opinion?

# src/AppBundle/Resources/config/api_resources/resources.yml
AppBundle\Entity\Answer:
    collectionOperations:
        api_questions_answer_get_subresource:
            method: 'GET' # nothing more to add if we want to keep the default controller
            path: '/foo/{id}/bar'

answer_get_subresource is the operation name

Was this page helpful?
0 / 5 - 0 ratings