File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,56 @@ App\Entity\Book:
169
169
```
170
170
[ /codeSelector]
171
171
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
+
172
222
API Platform Core is smart enough to automatically register the applicable Symfony route referencing a built-in CRUD action
173
223
just by specifying the method name as key, or by checking the explicitly configured HTTP method.
174
224
You can’t perform that action at this time.
0 commit comments