Created
August 25, 2017 15:02
-
-
Save dontpaniclabsgists/1b113a46a722d9c9d648c1588d955b29 to your computer and use it in GitHub Desktop.
azure_functions_1_2
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; | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
log.Info("C# HTTP trigger function processed a request."); | |
// parse query parameter | |
string name = req.GetQueryNameValuePairs() | |
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0) | |
.Value; | |
// Get request body | |
dynamic data = await req.Content.ReadAsAsync<object>(); | |
// Set name to query string or body data | |
name = name ?? data?.name; | |
return name == null | |
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body") | |
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment