Getting data out of Symfony REST API is one thing, but there's a strong chance that you will also need to add new data.
That's where the POST verb comes in to play.
In this video we will look at how to set up a basic POST action in FOS REST Bundle. The way we do this is to take the standard Symfony Request object that we get for free in our Controller actions and then use the Symfony Form component to do all the hard work.
The form component? I hear you say. But, we aren't doing anything with forms? And that's really where the magic of this methodology comes in to play. Well, it's not magic. It's actually pretty straightforward, but it's clever all the same, and likely not a way that you've thought about using the form component before.
We're going to start off adding all the logic into our Controller. That's a bit yacky, but stick with it as keeping it simple gives us a good basis for understanding the whole workflow. We can extract and modularise once we know it all works.
If you have found this video helpful, please consider sharing. I really appreciate it.
|3||GET Handled, thin Controllers and fun with Services||17:49|
|4||Automatic Route Generation||11:32|
|5||GETting a Collection||12:53|
|7||Acceptance Testing our POST Method||05:40|
|8||Unit Testing our Symfony Form||22:55|
|9||Implementing and Testing the Form Handler||03:01|
|10||POST Form Handler Implementation||11:12|