Skip to content

Commit d01d670

Browse files
authored
Update operations.md (#1214)
Hello, I just completed the code block with `yaml` and `xml` examples.
1 parent a49715e commit d01d670

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

core/operations.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ App\Entity\Book:
114114

115115
The previous example can also be written with an explicit method definition:
116116

117+
[codeSelector]
117118
```php
118119
<?php
119120
// api/src/Entity/Book.php
@@ -135,6 +136,39 @@ class Book
135136
}
136137
```
137138

139+
```yaml
140+
# api/config/api_platform/resources.yaml
141+
App\Entity\Book:
142+
collectionOperations:
143+
get:
144+
method: GET
145+
itemOperations:
146+
get:
147+
method: GET
148+
```
149+
150+
```xml
151+
<?xml version="1.0" encoding="UTF-8" ?>
152+
<!-- api/config/api_platform/resources.xml -->
153+
154+
<resources xmlns="https://api-platform.com/schema/metadata"
155+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
156+
xsi:schemaLocation="https://api-platform.com/schema/metadata
157+
https://api-platform.com/schema/metadata/metadata-2.0.xsd">
158+
<resource class="App\Entity\Book">
159+
<collectionOperations>
160+
<collectionOperation name="get" />
161+
</collectionOperations>
162+
<itemOperations>
163+
<itemOperation name="get">
164+
<attribute name="method">GET</attribute>
165+
</itemOperation>
166+
</itemOperations>
167+
</resource>
168+
</resources>
169+
```
170+
[/codeSelector]
171+
138172
API Platform Core is smart enough to automatically register the applicable Symfony route referencing a built-in CRUD action
139173
just by specifying the method name as key, or by checking the explicitly configured HTTP method.
140174

0 commit comments

Comments
 (0)