Skip to content

Instantly share code, notes, and snippets.

@ealsur
Last active January 19, 2018 15:11
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 ealsur/11411694f7e46f32cadded0b62c2a1bf to your computer and use it in GitHub Desktop.
Save ealsur/11411694f7e46f32cadded0b62c2a1bf to your computer and use it in GitHub Desktop.
Azure Cosmos DB + Functions Cookbook - HTTP query csx
#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