> For the complete documentation index, see [llms.txt](/llms.txt)

# Pagination

Paginated list methods expose the language's iteration surface. In TypeScript,
`for await` fetches pages as you consume their items:

**TypeScript** (regenerated + byte-diffed in CI `a0f8af4b462c`)

```ts
import { Client } from 'glotto-sdk';

const client = new Client({ token: '<token>' });
for await (const item of client.pets.listPets()) {
  console.log(item);
}
```

**React Native** (regenerated + byte-diffed in CI `a1fefe7d3458`)

```ts
import { Client } from 'glotto-sdk';

const client = new Client({ token: '<token>' });
for await (const item of client.pets.listPets()) {
  console.log(item);
}
```

**Python** (regenerated + byte-diffed in CI `2242160f8958`)

```python
from glotto_sdk import Client

client = Client(token="<token>")
for item in client.pets.list_pets():
    print(item)
```

**Go** (regenerated + byte-diffed in CI `f0c565cc46f8`)

```go
package main

import (
    "context"
    "fmt"

    sdk "example.com/glotto-sdk-go"
)

func main() {
    ctx := context.Background()
    client := sdk.NewClient(sdk.WithToken("<token>"))
    for value, err := range client.Pets.ListPetsIter(ctx) {
        if err != nil {
            panic(err)
        }
        fmt.Println(value)
    }
}
```

**Java** (regenerated + byte-diffed in CI `12c05e098737`)

```java
import com.glotto.Client;

public class Snippet {
    public static void main(String[] args) throws Exception {
        Client client = Client.builder().token("<token>").build();
        try (var stream = client.pets().listPets()) {
            stream.forEach(System.out::println);
        }
    }
}
```

**Kotlin** (regenerated + byte-diffed in CI `0f5e53ae2522`)

```kotlin
import com.glotto.Client
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.flow.collect

fun main() = runBlocking {
    val client = Client(token = "<token>")
    client.pets.listPets().collect { println(it) }
}
```

**C#** (regenerated + byte-diffed in CI `c5013ce0e88b`)

```csharp
using Glotto;

var client = new Glotto.Client("<token>");
await foreach (var item in client.Pets.ListPets())
{
    Console.WriteLine(item);
}
```

**PHP** (regenerated + byte-diffed in CI `1acd16081b46`)

```php
<?php
require 'vendor/autoload.php';

$client = new Glotto\Client(token: '<token>');
foreach ($client->pets->listPetsIterator() as $item) {
    var_dump($item);
}
```

**Ruby** (regenerated + byte-diffed in CI `a2b854f6593f`)

```ruby
require 'glotto'

client = Glotto::Client.new(token: '<token>')
client.pets.list_pets().each do |item|
  puts item
end
```

**Rust** (regenerated + byte-diffed in CI `716e9ec181d1`)

```rust
use futures::StreamExt;

let client = Client::default().with_token("<token>");
let mut stream = StreamScope::new(client.pets().list_pets().into_stream());
while let Some(item) = stream.next().await {
    println!("{:?}", item?);
}
stream.close();
```

**Swift** (regenerated + byte-diffed in CI `0cc357352baf`)

```swift
import Foundation
import GlottoSdk

let client = Client(token: "<token>")
let stream = client.pets.listPetsScoped()
defer { stream.close() }
for try await item in stream {
    print(item)
}
```

**Dart** (regenerated + byte-diffed in CI `67567d6df435`)

```dart
import 'package:glotto_sdk/glotto_sdk.dart';

final client = Client(token: "<token>");
try {
  await for (final item in client.pets.listPets()) {
    print(item);
  }
} finally {
  client.close();
}
```

**Elixir** (regenerated + byte-diffed in CI `b97af402f1d7`)

```elixir
client = Glotto.new(token: "<token>")
Glotto.Pets.list_pets(client) |> Enum.each(&IO.inspect/1)
```

> These are byte-for-byte outputs from the same per-language snippet emitters used by
> `glotto generate`, locked to a paginated petstore fixture by a drift test. Your generated version
> substitutes the package identity, operation name, parameters, authentication scheme, and pagination
> shape derived from your spec and `glotto.yml`.

Glotto supports **cursor**, **cursor-id**, **page**, **offset**, and **link-header**
pagination. An incomplete declaration stays an ordinary request method: the SDK
does not invent the missing navigation fields.

## Fetch one page

Each supported paginator also has a manual page operation. It fetches one page
and exposes its items, response metadata, HTTP response headers, and whether another page exists.
Reading those values sends no requests. Fetch the next page explicitly when
your application is ready; the next-page call accepts request overrides.

The generated README shows the names and types for your language and API. The
automatic iterator uses this same page-fetch operation, so both approaches
share authentication, retries, errors, and pagination rules. A typed full-response
accessor can report a decoding error if the server returns malformed metadata;
reading it does not make another request.

An absolute next link is the server's complete navigation URL. The SDK follows
it without adding the previous page's filters again. Explicit query overrides
on your next-page call can augment that URL.
