Skip to content

Instantly share code, notes, and snippets.

@jessebarocio

jessebarocio/GetRecords.cs Secret

Last active Oct 26, 2018
Embed
What would you like to do?
[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