POSTing 101


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.

Code For This Course

Get the code for this course.

Code For This Video

Get the code for this video.

Episodes