The GetCities method of our CitiesController returns a JSON array of all the ~13,000 cities in our database by default; that's definitely a no-go in terms of server-side performance, so we need to change it. Ideally, we would like to only return a small number of Cities, which is something we can easily pull off by adding some (required) variables in the method signature, such as pageIndex and pageSize.

Here's how we could change that to enforce such behavior (updated lines highlighted):

// ...existing code...[HttpGet]public async Task<ActionResult<IEnumerable<City>>> GetCities(    int pageIndex = 0,     int pageSize = 10){    return await _context.Cities                .Skip(pageIndex * pageSize)                .Take(pageSize)                .ToListAsync();}// ...existing code... ...

Get ASP.NET Core 3 and Angular 9 - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.