Skip to content

Commit a49715e

Browse files
authored
Update operations.md (#1215)
Hello, I just add `yaml` and `xml` examples.
1 parent 47fc291 commit a49715e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

core/operations.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ just by specifying the method name as key, or by checking the explicitly configu
140140

141141
If you do not want to allow access to the resource item (i.e. you don't want a `GET` item operation), instead of omitting it altogether, you should instead declare a `GET` item operation which returns HTTP 404 (Not Found), so that the resource item can still be identified by an IRI. For example:
142142

143+
[codeSelector]
143144
```php
144145
<?php
145146
// api/src/Entity/Book.php
@@ -168,6 +169,42 @@ use ApiPlatform\Core\Annotation\ApiResource;
168169
}
169170
```
170171

172+
```yaml
173+
# api/config/api_platform/resources.yaml
174+
App\Entity\Book:
175+
collectionOperations:
176+
get: ~
177+
itemOperations:
178+
get:
179+
controller: App\Controller\NotFoundAction
180+
read: false
181+
output: false
182+
```
183+
184+
```xml
185+
<?xml version="1.0" encoding="UTF-8" ?>
186+
<!-- api/config/api_platform/resources.xml -->
187+
188+
<resources xmlns="https://api-platform.com/schema/metadata"
189+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
190+
xsi:schemaLocation="https://api-platform.com/schema/metadata
191+
https://api-platform.com/schema/metadata/metadata-2.0.xsd">
192+
<resource class="App\Entity\Book">
193+
<collectionOperations>
194+
<collectionOperation name="get" />
195+
</collectionOperations>
196+
<itemOperations>
197+
<itemOperation name="get">
198+
<attribute name="controller">App\Controller\NotFoundAction</attribute>
199+
<attribute name="read">false</attribute>
200+
<attribute name="output">false</attribute>
201+
</itemOperation>
202+
</itemOperations>
203+
</resource>
204+
</resources>
205+
```
206+
[/codeSelector]
207+
171208
## Configuring Operations
172209

173210
The URL, the method and the default status code (among other options) can be configured per operation.

0 commit comments

Comments
 (0)