API Platform Conference 2023 - Ryan Weaver - Create the DTO system of your dreams
ฝัง
- เผยแพร่เมื่อ 10 ก.ย. 2024
- One of the best features of API Platform is the ability to add #[ApiResource] above an entity and… bam! You have a fully-functional API! Though, if you want to have full control and peak clarity, nothing beats creating a dedicated DTO class.
But, creating a DTO class - especially when the data comes from Doctrine - feelslike reinventing the wheel! Suddenly you need to create a state provider, stateprocessor and filters… which all do the same thing that API Platform does automatically for entities.
No more! In this talk, we’ll explore a new feature called “state options” that gives you the flexibility of a DTO class, but the convenience of an entity. We’ll explore how this works & exactly what you need (e.g. a mapper system) to create a DTO class and have it “just work”.
_________
More info: api-platform.c...
X/Twitter: / apiplatform
Music credits: Solar Flare, Adi Goldstein
So do you put now the security annotations on the DTO in this case or still the entity cause this is what the Provider/Processor is calling?
We did something quite similar in our project with API Platform 3 and the development process was very painful. Hopefully, we succeed with DTO / processor approach but it took much time to understand how it works with a lack of documentation.
One of the weirdest things was that we had to expose entity resource and output DTO for this entity as a resource too (GET item only) to make it work.
Then, to create the one resource from those two (dto and entity) you have to use the same shortName and uriTemplate to fix openapi schema
I didn`t try stateOptions and it might solve this issue.
But in general, it is very far from DTO system of "my dreams" :)
Aussi passionnant que les sf casts !