Skip to content

Commit d8a307b

Browse files
authored
Update operations.md (#1253)
1 parent 398eaaa commit d8a307b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

core/operations.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,56 @@ App\Entity\Book:
169169
```
170170
[/codeSelector]
171171

172+
You can also disable all operations for an item or a collection. This example disables every item-related routes (PUT, GET, DELETE):
173+
174+
[codeSelector]
175+
```php
176+
<?php
177+
// api/src/Entity/Book.php
178+
179+
namespace App\Entity;
180+
181+
use ApiPlatform\Core\Annotation\ApiResource;
182+
183+
/**
184+
* ...
185+
* @ApiResource(
186+
* collectionOperations={"get"},
187+
* itemOperations={}
188+
* )
189+
*/
190+
class Book
191+
{
192+
// ...
193+
}
194+
```
195+
196+
```yaml
197+
# api/config/api_platform/resources.yaml
198+
App\Entity\Book:
199+
collectionOperations:
200+
get: ~ # nothing more to add if we want to keep the default controller
201+
itemOperations: []
202+
```
203+
204+
```xml
205+
<?xml version="1.0" encoding="UTF-8" ?>
206+
<!-- api/config/api_platform/resources.xml -->
207+
208+
<resources xmlns="https://api-platform.com/schema/metadata"
209+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
210+
xsi:schemaLocation="https://api-platform.com/schema/metadata
211+
https://api-platform.com/schema/metadata/metadata-2.0.xsd">
212+
<resource class="App\Entity\Book">
213+
<collectionOperations>
214+
<collectionOperation name="get" />
215+
</collectionOperations>
216+
<itemOperations />
217+
</resource>
218+
</resources>
219+
```
220+
[/codeSelector]
221+
172222
API Platform Core is smart enough to automatically register the applicable Symfony route referencing a built-in CRUD action
173223
just by specifying the method name as key, or by checking the explicitly configured HTTP method.
174224

0 commit comments

Comments
 (0)