GETting a Collection

This video is available to view for members only.

Click here to Join!

Already a member?

Login


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 $limit and $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 $limit and $offset parameters.

And with that we are well on our way to a well tested Symfony REST API.


Code For This Course

Get the code for this course.

Share This Episode

If you have found this video helpful, please consider sharing. I really appreciate it.


Episodes in this series

# Title Duration
1 GETting Started 17:06
2 GETting Refactored 15:39
3 GET Handled, thin Controllers and fun with Services 17:49
4 Automatic Route Generation 11:32
5 GETting a Collection 12:53
6 POSTing 101 11:06
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
11 PUT Introduction 07:34
12 PUT Implementation 15:25
13 Pragmatic PATCH 15:17
14 DELETE'ing Things 03:30