Last active
January 19, 2018 15:11
-
-
Save ealsur/11411694f7e46f32cadded0b62c2a1bf to your computer and use it in GitHub Desktop.
Azure Cosmos DB + Functions Cookbook - HTTP query csx
This file contains hidden or 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
#r "System.Runtime.Serialization" | |
using System.Net; | |
using System.Runtime.Serialization; | |
// Define the class that will get sent on the HTTP body | |
// DataContract is used to support XML | |
[DataContract(Name = "Query", Namespace = "http://functions")] | |
public class Query { | |
[DataMember] | |
public string Name { get; set; } | |
[DataMember] | |
public string City { get; set; } | |
} | |
public static async Task<HttpResponseMessage> Run(Query query, HttpRequestMessage req, IEnumerable<dynamic> documents, TraceWriter log) | |
{ | |
int totalDocuments = documents.Count(); | |
log.Info($"Found {totalDocuments} documents"); | |
if(totalDocuments == 0){ | |
return req.CreateResponse(HttpStatusCode.NotFound); | |
} | |
return req.CreateResponse(HttpStatusCode.OK, documents); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment