diff --git a/core/getting-started.md b/core/getting-started.md index 694214a1124..14e4fc5f8f0 100644 --- a/core/getting-started.md +++ b/core/getting-started.md @@ -183,7 +183,7 @@ resources: - @@ -196,7 +196,7 @@ resources: https://schema.org/Offer - + ``` diff --git a/core/operations.md b/core/operations.md index 6753a31c900..5ac8969d9d1 100644 --- a/core/operations.md +++ b/core/operations.md @@ -440,6 +440,100 @@ book_post_publication: _api_operation_name: post_publication ``` +## Defining Which Operation to Use to Generate the IRI + +Using multiple operations on your resource, you may want to specify which operation to use to generate the IRI, instead +of letting API Platform use the first one it finds. + +Let's say you have 2 resources in relationship: `Company` and `User`, where a company has multiple users. You can declare +the following routes: + +- `/users` +- `/users/{id}` +- `/companies/{companyId}/users` +- `/companies/{companyId}/users/{id}` + +The first routes (`/users...`) are only accessible by the admin, and the others by regular users. Calling +`/companies/{companyId}/users` should return IRIs matching `/companies/{companyId}/users/{id}` to not expose an admin +route to regular users. + +To do so, use the `itemUriTemplate` option only available on `GetCollection` and `Post` operations: + +[codeSelector] + +```php + + + + + + + + + + + + + + + + + + + +``` + +[/codeSelector] + +API Platform will find the operation matching this `itemUriTemplate` and use it to generate the IRI. + +If this option is not set, the first `Get` operation is used to generate the IRI. + ## Expose a Model Without Any Routes Sometimes, you may want to expose a model, but want it to be used through subrequests only, and never through item or collection operations.