Last active
May 22, 2018 15:36
-
-
Save yokawasa/90b832251e728139cb9a411bd51fd71f to your computer and use it in GitHub Desktop.
Azure Function HTTP Trigger Function Sample
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
using System.Net; | |
using Newtonsoft.Json; | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
log.Info("C# HTTP trigger function to process fluentd output request."); | |
log.Info( string.Format("Dump request:\n {0}",req.ToString())); | |
// parse query parameter | |
string payload = req.GetQueryNameValuePairs() | |
.FirstOrDefault(q => string.Compare(q.Key, "payload", true) == 0) | |
.Value; | |
// Get request body | |
dynamic data = await req.Content.ReadAsAsync<object>(); | |
if (data.payload == null) { | |
log.Info("Please pass a payload on the query string or in the request body"); | |
return new HttpResponseMessage(HttpStatusCode.BadRequest); | |
} | |
// Process Your Jobs! | |
dynamic r = JsonConvert.DeserializeObject<dynamic>((string)data.payload); | |
if (r.key1!=null) log.Info(string.Format("key1={0}",r.key1)); | |
if (r.key2!=null) log.Info(string.Format("key2={0}",r.key2)); | |
if (r.key3!=null) log.Info(string.Format("key3={0}",r.key3)); | |
if (r.mytime!=null) log.Info(string.Format("mytime={0}",r.mytime)); | |
if (r.mytag!=null) log.Info(string.Format("mytag={0}",r.mytag)); | |
return new HttpResponseMessage(HttpStatusCode.OK); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Azure Function HTTP Trigger Function Sample:
https://github.com/yokawasa/fluent-plugin-azurefunctions/tree/master/examples/function-csharp