Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save guitarrapc/3fd91076d0a862fcb373760bd11729d6 to your computer and use it in GitHub Desktop.
Save guitarrapc/3fd91076d0a862fcb373760bd11729d6 to your computer and use it in GitHub Desktop.
#r "Newtonsoft.Json"
using System;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
{
log.Verbose($"Webhook was triggered!");
string jsonContent = await req.Content.ReadAsStringAsync();
dynamic data = JsonConvert.DeserializeObject(jsonContent);
if (data.first == null || data.last == null) {
return req.CreateResponse(HttpStatusCode.BadRequest, new {
error = "Please pass first/last properties in the input object"
});
}
var extensionMethodTest = Enumerable.Range(1, 11).Select(x => x * 10).ToArray().ToJoinedString(",");
return req.CreateResponse(HttpStatusCode.OK, new {
greeting = $"Hello {data.first} {data.last} and {extensionMethodTest}!"
});
}
public static string ToJoinedString<T>(this IEnumerable<T> source, string separator = "")
{
return string.Join(separator, source);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment