Now we know how to GET a single record from our Symfony REST API, the next logical step is to return multiple records. That's where our Collection resource comes in to play.
Conceptually this isn't hugely different from returning a single record. We want to call one of our API end-points (though this would be a different from the single record end-point) and then return an array of results.
Because we have followed a sensible structure to our project, implementing this feature is straightforward. Which is nice.
We're going with our REST API testing approach and begin by writing our new tests to cover the end point. From there we can go ahead and implement the feature with confidence.
Then we will add in a way to limit the amount of results that are returned, and make a start on giving our API consumer a way to paginate the result set. We do this using a
$offset. We're going to use the FOS REST Bundle QueryParam annotations for this. This has a little gotcha' associated with it that I routinely forget, so we cover the error message you will see and then the quick fix for how to rectify it.
Lastly we cover off how to set up some sensible defaults for our
And with that we are well on our way to a well tested Symfony REST API.
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|