PUT Introduction


In this video we are going to be looking at the PUT verb of our Symfony 2 and FosRestBundle API.

As a high level overview, PUT would be used to completely replace an existing record in our database OR it would be create a new record for us, if the ID we are PUT'ting to does not already exist.

We are going to start with some failing tests and work our way through until they are all passing.

Firstly we will want to ensure that a PUT with both an invalid ID and invalid data should fail gracefully with a 400 error code.

Secondly, we want to ensure that even if we use an invalid ID but are submitting valid data that the data should be kept and a valid ID assigned and returned.

Thirdly, we want to ensure that invalid data cannot be PUT over the top of an existing valid id / record.

And lastly we want to ensure that if we have a valid ID and valid data, that the existing record is replaced entirely (keeping the same ID) with the submitted data.

By the end of this video you will have an established test base for implementing PUT into a Symfony2 FosRestBundle-based API.

Code For This Course

Get the code for this course.

Code For This Video

Get the code for this video.

Episodes