Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for continuation tokens #15

Open
johnbatty opened this issue Aug 5, 2022 · 4 comments
Open

Add support for continuation tokens #15

johnbatty opened this issue Aug 5, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@johnbatty
Copy link
Collaborator

Operations that return many items use continuation tokens to allow the items to be returned in batches.

REST responses that do not contain all items include an HTTP header x-ms-continuationtoken that provides a continuation token value. This value must be provided on a subsequent call as a continuationToken parameter to query the remaining items (repeated as necessary until the server does not include the x-ms-continuationtoken header).

The Python SDK has a "response" object that includes the continuation token, with the actual response as a value field.

The Rust SDK already modifies the spec to handle responses that return lists of items, as the server sends them in a wrapper:

{
   count: Option<i32>,
   value: Vec<type>
} <type>List

We could change this to include the continuation token as per the Python SDK (and perhaps change our wrapper type to be <...>Response rather than <...>List.

{
   count: Option<i32>,
   value: Vec<type>
   continuation_token: Option<String>
} <type>Response

Deserialization of this struct from the protocol would still work because the continuation_token field is declared as an Option, so would always be set to None as the field is in the headers rather than the body. However, we could modify the code generator to fill in this value from the response headers before the value is returned to the application.

Useful links:

@johnbatty johnbatty added the enhancement New feature or request label Aug 5, 2022
@johnbatty
Copy link
Collaborator Author

johnbatty commented Aug 8, 2022

Worth noting that the Azure SDK has done some work in this area, notably:

Need to decide whether we leverage this or just implement something similar to the Azure DevOps Python package.

@johnbatty
Copy link
Collaborator Author

A recent enhancement to the autorust enables access to headers on responses by using send() on requests rather than into_future(). This allows continuation tokens to be obtained by apps.

I'll update the docs and add an example to show how to do this.

@johnbatty
Copy link
Collaborator Author

Added an example that demonstrates how to do large queries with continuation tokens by using the new send() and raw_response() functions: build_list_continuation_token

@kyle-rader-msft
Copy link
Contributor

@johnbatty I'm curious on your thoughts about also handling pagination for APIs that don't use continuation tokens like the Git Commit Get Changes API, which only uses top and skip params, but doesn't have any indication if there are more results to fetch. You have to just attempt to fetch them yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants