ARTICLE AD BOX
I'm consuming a REST API that returns results in paginated responses (limit + page/offset). Currently, I'm looping through pages sequentially and aggregating results into a List<T>.
Example:
var results = new List<Item>(); int page = 1; while(true) { var response = await client.GetAsync($"api/items?page={page}"); var pageResult = await response.Content.ReadFromJsonAsync<ApiResponse>(); if (pageResult.Items.Count == 0) break; results.AddRange(pageResult.Items); page++; }So my question is: is there a recommended pattern in .NET for handling paginated APIs efficiently? Is it safe to fetch pages in parallel if the API supports it, and would something like IAsyncEnumerable be a better approach here?
