liveBook · Manning

Server-side paging

As explained in Building Web APIs with ASP.NET Core

Server-side paging returns only the subset of records requested for a page.

Server-side paging populates each client page by requesting only its relevant records from the web API, instead of downloading the complete dataset. section 5.4.1

Implement paging with three values:

  • PageIndex: a zero-based page number passed by the client; the first page is 0. section 5.4.1
  • PageSize: the number of records per page, supplied by the client or constrained by the server. section 5.4.1
  • RecordCount: the server-calculated total, allowing the client to determine available pages or records. section 5.4.1
Listing 5.5 BoardGameController.Get() method (with paging)
[HttpGet(Name = "GetBoardGames")]
[ResponseCache(Location = ResponseCacheLocation.Any, Duration = 60)]
public async Task<RestDTO<BoardGame[]>> Get(
    int pageIndex = 0,
int pageSize = 10)
{
    var query = _context.BoardGames
.Skip(pageIndex * pageSize)
.Take(pageSize);
 
    return new RestDTO<BoardGame[]>()
    {
        Data = await query.ToArrayAsync(),
PageIndex = pageIndex,
PageSize = pageSize,
RecordCount = await _context.BoardGames.CountAsync(),
        Links = new List<LinkDTO> {
            new LinkDTO(
                Url.Action(
                    null,
                    "BoardGames",
new { pageIndex, pageSize },
                    Request.Scheme)!,
                "self",
                "GET"),
        }
    };
}

The BoardGames endpoint applies Skip(pageIndex * pageSize) and Take(pageSize), then returns the selected data with paging metadata and a self link. section 5.4.1

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains the three paging values and demonstrates Skip, Take, metadata, and links, without detailing validation or performance safeguards.
Examples
Uses the BoardGames endpoint with default pageIndex 0, pageSize 10, Skip, Take, RestDTO properties, and a self link.
What it assumes
Assumes basic client-server and web API concepts while defining page indexes, page sizes, and record counts explicitly.
What you can do after
Apply it via endpoint parameters and query operations to return one page alongside its total record count.
How it connects
Connects server-side paging with client-side paging, web APIs, HTTP requests, query filtering, and response metadata.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.