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/controllers.md
+74-2Lines changed: 74 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,10 @@ In the following examples, the built-in `GET` operation is registered as well as
23
23
24
24
By default, API Platform uses the first `Get` operation defined to generate the IRI of an item and the first `GetCollection` operation to generate the IRI of a collection.
25
25
26
+
If your resource does not have any `Get` operation, API Platform automatically adds an operation to help generating this IRI.
27
+
If your resource has any identifier, this operation will look like `/books/{id}`. But if your resource doesn't have any identifier, API Platform will use the Skolem format `/.well-known/genid/{id}`.
28
+
Those routes are not exposed from any documentation (for instance OpenAPI), but are anyway declared on the Symfony routing and always return a HTTP 404.
29
+
26
30
If you create a custom operation, you will probably want to properly document it.
27
31
See the [OpenAPI](openapi.md) part of the documentation to do so.
28
32
@@ -56,7 +60,7 @@ class CreateBookPublication extends AbstractController
56
60
}
57
61
```
58
62
59
-
This custom operation behaves exactly like the built-in operation: it returns a JSON-LD document corresponding to the id
63
+
This custom operation behaves exactly like the built-in operation: it returns a JSON-LD document corresponding to the ID
60
64
passed in the URL.
61
65
62
66
Here we consider that [autowiring](https://symfony.com/doc/current/service_container/autowiring.html) is enabled for
@@ -144,9 +148,77 @@ App\Entity\Book:
144
148
145
149
[/codeSelector]
146
150
147
-
It is mandatory to set the `method`, `path` and `controller` attributes. They allow API Platform to configure the routing path and
151
+
It is mandatory to set the `method`, `uriTemplate` and `controller` attributes. They allow API Platform to configure the routing path and
148
152
the associated controller respectively.
149
153
154
+
## Using the PlaceholderAction
155
+
156
+
Complex use cases may lead you to create multiple custom operations.
157
+
158
+
In such a case, you will probably create the same amount of custom controllers while you may not need to perform custom logic inside.
159
+
160
+
To avoid that, API Platform provides the `ApiPlatform\Action\PlaceholderAction` which behaves the same when using the [built-in operations](operations.md#operations).
161
+
162
+
You just need to set the `controller` attribute with this class. Here, the previous example updated:
You may want different serialization groups for your custom operations. Just configure the proper `normalizationContext` and/or `denormalizationContext` in your operation:
Copy file name to clipboardExpand all lines: core/dto.md
+76Lines changed: 76 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,7 @@ And the processor:
43
43
namespace App\State;
44
44
45
45
use App\Dto\UserResetPasswordDto;
46
+
use ApiPlatform\Metadata\Operation;
46
47
use ApiPlatform\State\ProcessorInterface;
47
48
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
48
49
@@ -107,6 +108,7 @@ namespace App\State;
107
108
108
109
use App\Dto\AnotherRepresentation;
109
110
use App\Model\Book;
111
+
use ApiPlatform\Metadata\Operation;
110
112
use ApiPlatform\State\ProviderInterface;
111
113
112
114
final class BookRepresentationProvider implements ProviderInterface
@@ -117,3 +119,77 @@ final class BookRepresentationProvider implements ProviderInterface
117
119
}
118
120
}
119
121
```
122
+
123
+
## Implementing a Write Operation With an Output Different From the Resource
124
+
125
+
For returning another representation of your data in a [State Processor](./state-processors.md), you should specify your processor class in the `processor` attribute and same for your `output`.
Copy file name to clipboardExpand all lines: core/elasticsearch.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -199,6 +199,8 @@ Keep in mind that it is your responsibility to populate your Elasticsearch index
199
199
a custom [state processors](state-processors.md#creating-a-custom-state-processor) or any other mechanism that suits your
200
200
project (such as an [ETL](https://en.wikipedia.org/wiki/Extract,_transform,_load)).
201
201
202
+
To disable elasticsearch index discovery for non-elasticsearch entities you can set `elasticsearch: false` in the `#[ApiResource]` attribute. If this property is absent, all entities will perform an index check during cache warmup to determine if they are on elasticsearch or not.
Copy file name to clipboardExpand all lines: core/extending.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,9 +15,9 @@ The following tables summarizes which extension point to use depending on what y
15
15
|[State Processors](state-processors)| custom business logic and computations to trigger before or after persistence (ex: mail, call to an external API...) |
16
16
|[Normalizers](serialization.md#decorating-a-serializer-and-adding-extra-data)| customize the resource sent to the client (add fields in JSON documents, encode codes, dates...) |
17
17
|[Filters](filters.md)| create filters for collections and automatically document them (OpenAPI, GraphQL, Hydra) |
18
-
|[Serializer Context Builders](serialization.md#changing-the-serialization-context-dynamically)|Changing the Serialization context (e.g. groups) dynamically |
18
+
|[Serializer Context Builders](serialization.md#changing-the-serialization-context-dynamically)|change the Serialization context (e.g. groups) dynamically |
19
19
|[Messenger Handlers](messenger.md)| create 100% custom, RPC, async, service-oriented endpoints (should be used in place of custom controllers because the messenger integration is compatible with both REST and GraphQL, while custom controllers only work with REST) |
20
-
|[DTOs and Data Transformers](dto.md)| use a specific class to represent the input or output data structure related to an operation |
20
+
|[DTOs](dto.md)| use a specific class to represent the input or output data structure related to an operation |
21
21
|[Kernel Events](events.md)| customize the HTTP request or response (REST only, other extension points must be preferred when possible) |
Copy file name to clipboardExpand all lines: core/filters.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -951,7 +951,7 @@ App\Entity\Tweet:
951
951
952
952
[/codeSelector]
953
953
954
-
Given that the collection endpoint is `/tweets`, you can filter tweets by id and date in ascending or descending order:
954
+
Given that the collection endpoint is `/tweets`, you can filter tweets by ID and date in ascending or descending order:
955
955
`/tweets?order[id]=asc&order[date]=desc`.
956
956
957
957
By default, whenever the query does not specify the direction explicitly (e.g: `/tweets?order[id]&order[date]`), filters
@@ -1173,8 +1173,8 @@ to retrieve items, [extensions](extensions.md) are the way to go.
1173
1173
A Doctrine ORM filter is basically a class implementing the `ApiPlatform\Doctrine\Orm\Filter\FilterInterface`.
1174
1174
API Platform includes a convenient abstract class implementing this interface and providing utility methods: `ApiPlatform\Doctrine\Orm\Filter\AbstractFilter`.
1175
1175
1176
-
In the following example, we create a class to filter a collection by applying a regexp to a property. The `REGEXP` DQL
1177
-
function used in this example can be found in the [`DoctrineExtensions`](https://github.com/beberlei/DoctrineExtensions)
1176
+
In the following example, we create a class to filter a collection by applying a regular expression to a property.
1177
+
The `REGEXP` DQL function used in this example can be found in the [`DoctrineExtensions`](https://github.com/beberlei/DoctrineExtensions)
1178
1178
library. This library must be properly installed and registered to use this example (works only with MySQL).
1179
1179
1180
1180
```php
@@ -1191,7 +1191,7 @@ use Symfony\Component\PropertyInfo\Type;
0 commit comments