Filtering, sorting, and pagination
In this section of the book we’re going to focus on building up the functionality for a new GET /v1/movies endpoint, which will return the details of multiple movies in a JSON array.
| Method | URL Pattern | Handler | Action |
|---|---|---|---|
| GET | /v1/healthcheck | healthcheckHandler | Show application information |
| GET | /v1/movies | listMoviesHandler | Show the details of all movies |
| POST | /v1/movies | createMovieHandler | Create a new movie |
| GET | /v1/movies/:id | showMovieHandler | Show the details of a specific movie |
| PATCH | /v1/movies/:id | updateMovieHandler | Update the details of a specific movie |
| DELETE | /v1/movies/:id | deleteMovieHandler | Delete a specific movie |
We’ll develop the functionality for this endpoint incrementally, starting out by returning data for all movies and then gradually making it more useful and usable by adding filtering, sorting, and pagination functionality.
In this section you’ll learn how to:
Return the details of multiple resources in a single JSON response.
Accept and apply optional filter parameters to narrow down the returned data set.
Implement full-text search on your database fields using PostgreSQL’s inbuilt functionality.
Accept and safely apply sort parameters to change the order of results in the data set.
Develop a pragmatic reusable pattern to support pagination on large data sets, and return pagination metadata in your JSON responses.