Skip to content

Instantly share code, notes, and snippets.

@jessebarocio
Last active October 26, 2018 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessebarocio/c8369763c032bf01664109125b04129a to your computer and use it in GitHub Desktop.
Save jessebarocio/c8369763c032bf01664109125b04129a to your computer and use it in GitHub Desktop.
[FunctionName("GetRecords")]
public static async Task<IActionResult> GetRecords(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "records")]
HttpRequest req,
[CosmosDB(databaseName: "Records", collectionName: "records", ConnectionStringSetting = "CosmosDBConnection")]
DocumentClient client)
{
var queryParams = req.GetQueryParameterDictionary();
// Maximum records to return (default to 50)
var count = Int32.Parse(queryParams.FirstOrDefault(q => q.Key == "count").Value ?? "50");
// Continuation token (for paging)
var continuationToken = queryParams.FirstOrDefault(q => q.Key == "continuationToken").Value;
// Build query options
var feedOptions = new FeedOptions()
{
MaxItemCount = count,
RequestContinuation = continuationToken
};
var uri = UriFactory.CreateDocumentCollectionUri("Records", "records");
var query = client.CreateDocumentQuery(uri, feedOptions)
.AsDocumentQuery();
var results = await query.ExecuteNextAsync();
return new OkObjectResult(new
{
hasMoreResults = query.HasMoreResults,
pagingToken = query.HasMoreResults ? results.ResponseContinuation : null,
results = results.ToList()
});
}
{
"hasMoreResults": true,
"pagingToken": "{\"token\":\"AV40ANomRkpkAAAAAAAAAA==\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}",
"results": [{ }]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment