The new C# v4 SDKs now support pagination, covering the four widely-used strategies: Offset, Page, Cursor, and Link based pagination. This provides a seamless and unified way to consume paginated API responses, regardless of the underlying mechanism.
Details
Paginated responses are common in REST APIs to improve performance and manage large datasets. With the pagination support, C# v4 SDKs automatically detect and handle paginated data based on the OpenAPI specification. This removes the need for manual pagination logic and gives developers a consistent interface to work with.
Each pagination type can be enabled independently using the pagination OpenAPI extension in the OpenAPI specification. Each pagination configuration allows customization of request and response fields using JSON Pointers, giving you full control over how pagination is applied for your specific API format.
Usage Example
The C# SDK provides a consistent interface across all pagination types. The endpoint function returns a Pageable that you consume asynchronously with await foreach. Iterate it directly to walk every item across all pages:
var transactions = client.ListTransactions(pageSize: 25);
try
{
// Iterate over every transaction across all pages.
await foreach (var transaction in transactions)
{
Console.WriteLine(transaction.Id);
}
}
catch (SdkException<RawError> ex)
{
Console.WriteLine(ex.Error.ReadAsString());
}
Alternatively, go page by page when you need per-page data or metadata:
var transactions = client.ListTransactions(pageSize: 25);
try
{
// Iterate one page at a time, reading each page's items and metadata.
await foreach (var page in transactions.AsPages())
{
Console.WriteLine($"Fetched {page.Data.Count} transactions in this page.");
}
}
catch (SdkException<RawError> ex)
{
Console.WriteLine(ex.Error.ReadAsString());
}
Regardless of the pagination type used in the API, the SDK standardizes the developer experience:
transactionsyields every item across all pages when iterated withawait foreach.transactions.AsPages()yields one page at a time, each exposing its items and any metadata the response returns, such as a next cursor or links.
Pagination tokens, page numbers, offsets, or links are automatically managed by the SDK, and pages are fetched only as you iterate over the results. This makes integration with paginated APIs straightforward, clean, and idiomatic.
Learn more about pagination feature
This feature is available in the C# v4 SDK (beta). Generate it from the APIMatic CLI:
apimatic sdk generate --language=csharp --codegen-version=v4 --stability=beta
For the full set of flags and options, see the APIMatic CLI documentation.