Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions fern/products/sdks/deep-dives/configure-auto-pagination.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,63 @@ results instead of managing pagination complexity manually.
print(user)
```
</Tab>
<Tab title="Go" language="go">

Once you've configured pagination for an endpoint, Fern generates a Go SDK
method that returns a `*core.Page[T]` where `T` is the underlying data type.
`Page.Iterator()` returns an iterator that fetches subsequent pages as needed,
and `Page.GetNextPage(ctx)` iterates page by page.

```go
page, err := client.Users.List(ctx)
if err != nil {
return err
}
iter := page.Iterator()
for iter.Next(ctx) {
fmt.Println(iter.Current())
}
return iter.Err()
```

A page property that lives in the request body rather than in a query parameter
requires the [`enableRequestBodyPagination`](/learn/sdks/generators/go/configuration#enablerequestbodypagination)
configuration option.
</Tab>
<Tab title="Java" language="java">

Once you've configured pagination for an endpoint, Fern generates a Java SDK
method that returns a `SyncPagingIterable<T>` where `T` is the underlying data
type. The iterable fetches subsequent pages as your users loop over or stream
the items, and `nextPage()` paginates manually.

```java
SyncPagingIterable<User> response = client.users().list();
for (User user : response) {
System.out.println(user);
}
```

or as a stream:
```java
client.users().list().streamItems().forEach(System.out::println);
```
</Tab>
<Tab title="C#" language="csharp">

Once you've configured pagination for an endpoint, Fern generates a C# SDK
method that returns a `Pager<T>` where `T` is the underlying data type. The
`Pager<T>` implements `IAsyncEnumerable<T>`, allowing your users to use it in
an `await foreach` loop.

```csharp
var users = await client.Users.ListAsync();
await foreach (var user in users)
{
Console.WriteLine(user);
}
```
</Tab>
</Tabs>

## Setting up auto-pagination
Expand Down
4 changes: 4 additions & 0 deletions fern/products/sdks/generators/go/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ option.WithUserAgentAppInfo("partner-app", "3.1.0", "+https://partner.example")
```
</ParamField>

<ParamField path="enableRequestBodyPagination" type="boolean" default="false" required={false} toc={true}>
Generates [auto-pagination](/learn/sdks/deep-dives/auto-pagination) for endpoints whose cursor or offset page property is a top-level request body property (for example, `cursor: $request.cursor`). The generated pager advances the page by setting the field on the request object instead of on the query string. This defaults to `false` because enabling it changes the affected methods' return types from a response to a pager. Nested body page properties (for example, `cursor: $request.pagination.cursor`) are unsupported and still generate a plain, non-paginated method.
</ParamField>

<ParamField path="enableWireTests" type="boolean" default="true" required={false} toc={true}>
Generates [mock server (wire) tests](/learn/sdks/deep-dives/testing#mock-server-tests) to verify that the SDK sends the correct HTTP requests and correctly handles responses per the API spec. When enabled, Docker is required as a runtime dependency to run the generated tests.
</ParamField>
Expand Down
Loading