Paging
Remember that we are simulating an automobile buying and selling application. There can be literally hundreds of cars in our database. We need to add paging to our Get
endpoint so that when we get the list of vehicles, they don’t all come down at once. This will also give us something to validate.
To facilitate this, we need to know the following:
- How big the page is – that is, the number of cars on each page
- The index of the page the client wants to see
We’ll accomplish this by modifying our Get
endpoint to take two additional parameters:
pageOffset
pageSize
Both of these are int
data types, as shown here:
[HttpGet] public async Task<IEnumerable<Car>> Get([FromRoute] bool showDeleted, int pageNumber, int pageSize )
The first new parameter (pageNumber
) will tell Get
which page it is on, and the second (pageSize
) will tell how many rows to get. Let’s look at an example in Postman, as shown in...