PageResponse

public struct PageResponse<Element> : Decodable, Sendable where Element : Decodable, Element : Sendable

Generic paginated response wrapper for Horizon API list endpoints.

The Stellar Horizon API returns large result sets as pages to avoid overwhelming clients and servers. PageResponse provides the current page of results along with navigation links to access previous and next pages.

Pagination uses cursor-based navigation, where each record has a unique paging token. Results are ordered by the specified sort order (ascending or descending).

Example usage:

let sdk = StellarSDK()

// Get first page of transactions
let response = await sdk.transactions.getTransactions(
    limit: 20,
    order: .descending
)

switch response {
case .success(let page):
    // Process current page
    print("Fetched \(page.records.count) transactions")

    for transaction in page.records {
        print("Hash: \(transaction.hash)")
    }

    // Navigate to next page if available
    if page.hasNextPage() {
        let nextPage = await page.getNextPage()
        // Process next page...
    }

    // Or get cursor for later pagination
    if let nextLink = page.links.next?.href {
        // Save cursor from URL for later use
    }

case .failure(let error):
    print("Error: \(error)")
}

See also:

  • Result enum for paginated responses.

    See more

    Declaration

    Swift

    public enum ResponseEnum : Sendable
  • Pagination links for next/prev pages.

    Declaration

    Swift

    public var links: PagingLinksResponse
  • Array of records returned in this page.

    Declaration

    Swift

    public var records: [Element]
  • Creates a new instance by decoding from the given decoder.

    Declaration

    Swift

    public init(from decoder: Decoder) throws

    Parameters

    decoder

    The decoder containing the data

  • Creates a new instance with the provided records and pagination links.

    Declaration

    Swift

    public init(records: [Element], links: PagingLinksResponse)

    Parameters

    records

    The records for this page

    links

    The pagination links received from the Horizon API

  • Checks if there is a previous page available.

    Declaration

    Swift

    public func hasPreviousPage() -> Bool

    Return Value

    true if a previous page is available

  • Checks if there is a next page available.

    Declaration

    Swift

    public func hasNextPage() -> Bool

    Return Value

    true if a next page is available

  • getNextPage() Asynchronous

    Fetches the next page of results if available.

    Before calling this, make sure there is a next page available by calling hasNextPage(). If there is no next page available this function will respond with a HorizonRequestError.notFound error.

    Declaration

    Swift

    public func getNextPage() async -> PageResponse<Element>.ResponseEnum

    Return Value

    ResponseEnum with the next page of results, or an error

  • getPreviousPage() Asynchronous

    Fetches the previous page of results if available.

    Before calling this, make sure there is a previous page available by calling hasPreviousPage(). If there is no previous page available this function will respond with a HorizonRequestError.notFound error.

    Declaration

    Swift

    public func getPreviousPage() async -> PageResponse<Element>.ResponseEnum

    Return Value

    ResponseEnum with the previous page of results, or an error