June 13, 2024

0.10.1

(feat): Add support for cursor and offset pagination.

What’s new

  • Add support for cursor and offset pagination.

For example, consider the following endpoint /users endpoint:

1types:
2 User:
3 properties:
4 name: string
5
6 ListUserResponse:
7 properties:
8 next: optional<string>
9 data: list<User>
10
11service:
12 auth: false
13 base-path: /users
14 endpoints:
15 list:
16 path: ""
17 method: GET
18 pagination:
19 cursor: $request.starting_after
20 next_cursor: $response.next
21 results: $response.data
22 request:
23 name: ListUsersRequest
24 query-parameters:
25 starting_after: optional<string>
26 response: ListUsersResponse

The generated SyncPagingIterable<User> can then be used to traverse through the User objects:

1for (User user : client.users.list(...)) {
2 System.out.println(user);
3}

Or stream them:

1client.users.list(...).streamItems().map(user -> ...);

Or statically calling nextPage() to perform the pagination manually:

1SyncPagingIterable<User> pager = client.users.list(...);
2// First page
3System.out.println(pager.getItems());
4// Second page
5pager = pager.nextPage();
6System.out.println(pager.getItems());