17 Scaling collection endpoints with filters and pagination

 

This chapter covers

  • Designing filters, pagination, and sorting for APIs
  • Enhancing the PetSitter OpenAPI definition with these features

As the PetSitter application grows, a lot of jobs will eventually be posted in the system at the same time. Pet sitters will have a hard time going through all the job postings to find those they are interested in. Also, the API response for listing all jobs may get too large to handle and slow down the app. The PetSitter team realized this during their sprint planning in chapter 16. At that time they decided to implement filters and pagination to solve the issue. While discussing these, we’re also going to look at a third related topic: sorting.

Before we start with the API design, though, let’s make sure we’re all thinking about the same things when we refer to filtering, pagination, and sorting:

17.1 The problem

17.2 Designing filters

17.2.1 Projection filters

17.2.2 Selection filters

17.2.3 Handling nested schemas

17.2.4 Query languages

17.2.5 Special conventions

17.3 Filters for PetSitter

17.3.1 Finding filter fields

17.3.2 Adding filters to OpenAPI

17.3.3 Making a request

17.4 Designing pagination

17.4.1 Offset-based and page-based pagination

17.4.2 Cursor-based pagination

17.5 Pagination for PetSitter

17.5.1 Adding pagination to OpenAPI

17.5.2 Extending our request example