How to validate data in API Platform
1 June 2022 (Updated 1 June 2022)
In a nutshell
API Platform provides a bridge with the Symfony Validator component so adding its validation constraints / custom constraint to your entities is enough to validate user-submitted data.
How to apply validation
Add validation constraints
Add the Symfony Validator namespace:
And then add whatever constraint you need to whatever property:
Test validation works as expected
Make an invalid request:
And you should get a 422
response that looks something like:
Sources
Tagged:
API Platform
Thanks for your comment ๐. Once it's approved, it will appear here.
Leave a comment