Skip to content

Commit 3acfedd

Browse files
authored
fix: add PATCH operation where it should be (#1393)
1 parent 2a711d9 commit 3acfedd

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

core/controllers.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ This action will be automatically registered as a service (the service name is t
6666
`App\Controller\CreateBookPublication`).
6767

6868
API Platform automatically retrieves the appropriate PHP entity using the data provider then deserializes user data in it,
69-
and for `POST` and `PUT` requests updates the entity with data provided by the user.
69+
and for `POST`, `PUT` and `PATCH` requests updates the entity with data provided by the user.
7070

7171
**Warning: when using `POST` or `PUT`, the `__invoke()` method parameter [MUST be called `$data`](https://symfony.com/doc/current/components/http_kernel.html#getting-the-controller-arguments)**, otherwise, it will not be filled correctly!
7272
When using `GET`, the `__invoke()` method parameter should be called the same as the entity identifier. So for the path `/user/{uuid}/bookmarks`, you must use `__invoke($uuid)`.

core/dto.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ services:
203203

204204
## Updating a Resource with a Custom Input
205205

206-
When performing an update (e.g. `PUT` operation), the resource to be updated is read by ApiPlatform before the deserialization phase. To do so, it uses a [data provider](data-providers.md) with the `:id` parameter given in the URL. The *body* of the request is the JSON object sent by the client, it is deserialized and is used to update the previously found resource.
206+
When performing an update (e.g. `PUT` operation), the resource to be updated is read by API Platform before the deserialization phase.
207+
To do so, it uses a [data provider](data-providers.md) with the `:id` parameter given in the URL.
208+
The *body* of the request is the JSON object sent by the client, it is deserialized and is used to update the previously found resource.
207209

208210
![Diagram put input output](images/diagrams/api-platform-put-i-o.svg)
209211

core/events.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ These built-in event listeners are registered for routes managed by API Platform
2525
Name | Event | [Pre & Post hooks](#custom-event-listeners) | Priority | Description
2626
------------------------------|--------------------|---------------------------------------------|----------|-------------
2727
`AddFormatListener` | `kernel.request` | None | 7 | Guesses the best response format ([content negotiation](content-negotiation.md))
28-
`ReadListener` | `kernel.request` | `PRE_READ`, `POST_READ` | 4 | Retrieves data from the persistence system using the [data providers](data-providers.md) (`GET`, `PUT`, `DELETE`)
29-
`DeserializeListener` | `kernel.request` | `PRE_DESERIALIZE`, `POST_DESERIALIZE` | 2 | Deserializes data into a PHP entity (`GET`, `POST`, `DELETE`); updates the entity retrieved using the data provider (`PUT`)
28+
`ReadListener` | `kernel.request` | `PRE_READ`, `POST_READ` | 4 | Retrieves data from the persistence system using the [data providers](data-providers.md) (`GET`, `PUT`, `PATCH`, `DELETE`)
29+
`DeserializeListener` | `kernel.request` | `PRE_DESERIALIZE`, `POST_DESERIALIZE` | 2 | Deserializes data into a PHP entity (`GET`, `POST`, `DELETE`); updates the entity retrieved using the data provider (`PUT`, `PATCH`)
3030
`DenyAccessListener` | `kernel.request` | None | 1 | Enforces [access control](security.md) using Security expressions
31-
`ValidateListener` | `kernel.view` | `PRE_VALIDATE`, `POST_VALIDATE` | 64 | [Validates data](validation.md) (`POST`, `PUT`)
32-
`WriteListener` | `kernel.view` | `PRE_WRITE`, `POST_WRITE` | 32 | Persists changes in the persistence system using the [data persisters](data-persisters.md) (`POST`, `PUT`, `DELETE`)
31+
`ValidateListener` | `kernel.view` | `PRE_VALIDATE`, `POST_VALIDATE` | 64 | [Validates data](validation.md) (`POST`, `PUT`, `PATCH`)
32+
`WriteListener` | `kernel.view` | `PRE_WRITE`, `POST_WRITE` | 32 | Persists changes in the persistence system using the [data persisters](data-persisters.md) (`POST`, `PUT`, `PATCH`, `DELETE`)
3333
`SerializeListener` | `kernel.view` | `PRE_SERIALIZE`, `POST_SERIALIZE` | 16 | Serializes the PHP entity in string [according to the request format](content-negotiation.md)
3434
`RespondListener` | `kernel.view` | `PRE_RESPOND`, `POST_RESPOND` | 8 | Transforms serialized to a `Symfony\Component\HttpFoundation\Response` instance
3535
`AddLinkHeaderListener` | `kernel.response` | None | 0 | Adds a `Link` HTTP header pointing to the Hydra documentation

core/operations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ class Weather
598598
// ...
599599
```
600600

601-
This will expose the `Weather` model, but also all the default CRUD routes: `GET`, `PUT`, `DELETE` and `POST`, which is a non-sense in our context.
601+
This will expose the `Weather` model, but also all the default CRUD routes: `GET`, `PUT`, `PATCH`, `DELETE` and `POST`, which is a non-sense in our context.
602602
Since we are required to expose at least one route, let's expose just one:
603603

604604
```php

core/security.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Available variables are:
121121
* `request`: the current request
122122

123123
Access control checks in the `security` attribute are always executed before the [denormalization step](serialization.md).
124-
It means than for `PUT` requests, `object` doesn't contain the value submitted by the user, but values currently stored in [the persistence layer](data-persisters.md).
124+
It means than for `PUT` or `PATCH` requests, `object` doesn't contain the value submitted by the user, but values currently stored in [the persistence layer](data-persisters.md).
125125

126126
## Executing Access Control Rules After Denormalization
127127

core/serialization.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Alternatively, you can use the more verbose syntax:
139139
```
140140

141141
In the previous example, the `name` property will be visible when reading (`GET`) the object, and it will also be available
142-
to write (`PUT/POST`). The `author` property will be write-only; it will not be visible when serialized responses are
142+
to write (`PUT` / `PATCH` / `POST`). The `author` property will be write-only; it will not be visible when serialized responses are
143143
returned by the API.
144144

145145
Internally, API Platform passes the value of the `normalization_context` as the 3rd argument of [the `Serializer::serialize()` method](https://api.symfony.com/master/Symfony/Component/Serializer/SerializerInterface.html#method_serialize) during the normalization
@@ -352,7 +352,7 @@ Instead of embedding relations in the main HTTP response, you may want [to "push
352352

353353
### Denormalization
354354

355-
It is also possible to embed a relation in `PUT` and `POST` requests. To enable that feature, set the serialization groups
355+
It is also possible to embed a relation in `PUT`, `PATCH` and `POST` requests. To enable that feature, set the serialization groups
356356
the same way as normalization. For example:
357357

358358
[codeSelector]

0 commit comments

Comments
 (0)