ameya
ameya

Reputation: 1668

What is the correct way to use Continuation token with Asp.net core Web API

I am using Azure Cosmos DB and Azure Storage Table with asp.net core 3.1 Table API. For both we can use the Continuation token for pagination and return large data in manageable chunks.

The ContinationToken has the following format: enter image description here

I also have the Web API that has a List API that returns the objects in chunks, the API asks user/developer to specify the limit (number of objects for e.g. 100) and if the database contains more that the specified limit it needs to return the continuation token to query next set of objects.

enter image description here

Now since the TableContinuationToken is a class, I take the token returned by the Table API and serialize it, encode it in Unicode bytes and return it to the user. This helps my API return the continuation token as a simple encoded string which user can easily pass for the next set of data.

enter image description here

This returns the token in a simple string format (e.g. eyJOZXh0UGFydGl0aW9uS2V5IjoiMSEyOCFTMlJpTTJWSk1HODRNRzFzTlRGMk9HaGFiak5CIiwiTmV4dFJvd0tleSI6IjEhMjAhZFc1cGRIUmxjM1J3Y205cVpXTjAiLCJOZXh0VGFibGVOYW1lIjpudWxsLCJUYXJnZXRMb2NhdGlvbiI6MH0)

It works well for me, but before I go production with this approach I want to check if this is the the correct way of using the TableContinuationToken and is there is any other built in way to get the continuation token as a simple string ?

And is there any time limit before the generated continuation token becomes invalid ?

Upvotes: 1

Views: 6318

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136369

It works well for me, but before I go production with this approach I want to check if this is the the correct way of using the TableContinuationToken and is there is any other built in way to get the continuation token as a simple string ?

As long as you can deserialize the string to get the continuation token back, I don't see any issues with your approach.

And is there any time limit before the generated continuation token becomes invalid ?

No, there's no time limit. A continuation token is based on the data being fetched for a particular query and you can use this token to fetch the next set of data. However you should keep this token value opaque in the sense that you should not try to infer the token value and build any business logic on that.

Upvotes: 1

Related Questions