Reputation: 11
I am trying to set up an API. I would like to use the default implementation of CRUD operations for GET requests and override the operations for POST, PUT and DELETE. That works actually very well already.
But my problem now is, that I would like to change the URL of the default implementation, so it fits to the URLs of my custom operations.
My Code looks something like that:
@ApiResource(
itemOperations={
"get",
"put"={
"path"="/my/very/important/URL/{id}",
"schemes"={"https"},
}
}
)
And I would now like to make the GET operation available through /my/very/important/URL
too, without implementing the GET operation.
Upvotes: 0
Views: 1569
Reputation: 61
According to the API Platform documentation:
"The URL, the method and the default status code (among other options) can be configured per operation. In the next example, both GET and POST operations are registered with custom URLs. Those will override the URLs generated by default. In addition to that, we require the id parameter in the URL of the GET operation to be an integer, and we configure the status code generated after successful POST request to be 301:"
https://api-platform.com/docs/core/operations/#configuring-operations
Here we have the example:
# api/config/api_platform/resources.yaml
App\Entity\Book:
collectionOperations:
post:
path: '/grimoire'
status: 301
itemOperations:
get:
method: 'GET'
path: '/grimoire/{id}'
requirements:
id: '\d+'
defaults:
color: 'brown'
host: '{subdomain}.api-platform.com'
schemes: ['https']
options:
my_option: 'my_option_value'
I hope it helps.
Upvotes: 0
Reputation: 11
I found a workaround for what I actually wanted to do: adding a route prefix at the entity.
* @ApiResource(
* routePrefix="/my/very/important/URL"
* )
But unfortunately I can still not prevent API Platform from using the plural of my entity name as URL.
If I have an entity Publication, than API Platform exposes my API with the URL /my/very/important/URL/publications
. I still don't know how to fix that.
Upvotes: 1