Member-only story
Symfony — Manage JSON API requests saving a lot of time
Automatic request content deserialization and validation
Do you ever felt like a monkey by repeating your code over and over again?
This was my situation using Symfony 5 without the support of FOSRestBundle. Decoding JSON request content and validate each field for each action of my controllers…was so frustrating!
So in the meanwhile FOSRestBundle making the support for the newer version of Symfony, I’ve decided to create a simple but useful bundle to automatically deserialize and validate the request content: IdenealRequestContentConverterBundle.
Behind the scenes
At the base of the workflow principle, there is the extension of ParamConverters of the SensioFrameworkExtraBundle. They are a way to populate objects and inject them as controller method arguments throw an annotation.
The ContentParamConverter has the purpose to deserialize the request content into an object previously defined and after that, validate…