Replies: 4 comments 1 reply
-
Isn't It does not seem like it's doing much "processing". From the mapping configuration, I would expect the processor would get a |
Beta Was this translation helpful? Give feedback.
-
@soyuka I can't find custom state provider page, even using relative path from dto page: |
Beta Was this translation helpful? Give feedback.
-
Thanks for the examples! It made me realize that it's even possible to use a "secondary" input DTO on top of a |
Beta Was this translation helpful? Give feedback.
-
My endpoint return {
"data": {
"id": 1,
"name": "john",
}
} How must be my Dto ? class ResponseDto
{
public array $data; // id and name properties ????
} |
Beta Was this translation helpful? Give feedback.
-
Using Data Transfer Objects (DTOs)
As stated in the general design considerations, in most cases the DTO pattern should be implemented using an API Resource class representing the public data model exposed through the API and a custom State Provider. In such cases, the class marked with
#[ApiResource]
will act as a DTO.However, it's sometimes useful to use a specific class to represent the input or output data structure related to an operation. These techniques are very useful to document your API properly (using Hydra or OpenAPI) and will often be used on
POST
operations.Implementing a Write Operation With an Input Different From the Resource
Using an input, the request body will be denormalized to the input instead of your resource class.
And the processor:
In some cases, using an input DTO is a way to avoid serialization groups.
Use Messenger With an Input DTO
Let's use a message that will be processed by Symfony Messenger. API Platform has an integration with messenger, to use a DTO as input you need to specify the
input
attribute:This will dispatch the
App\Dto\Message
via Symfony Messenger.Implementing a Read Operation With an Output Different From the Resource
To return another representation of your data in a State Provider we advise to specify the
output
attribute of the resource. Note that this technique works without any changes to the resource but your API documentation would be wrong.Beta Was this translation helpful? Give feedback.
All reactions