-
-
Save jessebarocio/c8369763c032bf01664109125b04129a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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() | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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