You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/operations.md
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,6 +63,8 @@ will be automatically added.
63
63
<?php
64
64
// api/src/Entity/Book.php
65
65
66
+
namespace App\Entity;
67
+
66
68
use ApiPlatform\Core\Annotation\ApiResource;
67
69
68
70
/**
@@ -84,6 +86,8 @@ The previous example can also be written with an explicit method definition:
84
86
<?php
85
87
// api/src/Entity/Book.php
86
88
89
+
namespace App\Entity;
90
+
87
91
use ApiPlatform\Core\Annotation\ApiResource;
88
92
89
93
/**
@@ -134,6 +138,36 @@ Or the XML configuration format:
134
138
API Platform Core is smart enough to automatically register the applicable Symfony route referencing a built-in CRUD action
135
139
just by specifying the method name as key, or by checking the explicitly configured HTTP method.
136
140
141
+
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:
142
+
143
+
```
144
+
<?php
145
+
// api/src/Entity/Book.php
146
+
147
+
namespace App\Entity;
148
+
149
+
use ApiPlatform\Core\Action\NotFoundAction;
150
+
use ApiPlatform\Core\Annotation\ApiResource;
151
+
152
+
/**
153
+
* @ApiResource(
154
+
* collectionOperations={
155
+
* "get",
156
+
* },
157
+
* itemOperations={
158
+
* "get"={
159
+
* "controller"=NotFoundAction::class,
160
+
* "read"=false,
161
+
* "output"=false,
162
+
* },
163
+
* },
164
+
* )
165
+
*/
166
+
class Book
167
+
{
168
+
}
169
+
```
170
+
137
171
## Configuring Operations
138
172
139
173
The URL, the method and the default status code (among other options) can be configured per operation.
@@ -145,6 +179,8 @@ In addition to that, we require the `id` parameter in the URL of the `GET` opera
145
179
<?php
146
180
// api/src/Entity/Book.php
147
181
182
+
namespace App\Entity;
183
+
148
184
use ApiPlatform\Core\Annotation\ApiResource;
149
185
150
186
/**
@@ -245,6 +281,8 @@ you don't need to override all the operations to set the path but configure the
0 commit comments