Created
April 6, 2016 01:17
-
-
Save itn3000/e9b4d05b426821c30842c3ffb1121f47 to your computer and use it in GitHub Desktop.
extension method in Azure Functions
This file contains 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 System.Threading.Tasks; | |
static string MyExtension(this int num) | |
{ | |
return "my extension"; | |
} | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
log.Verbose($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}"); | |
// 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 + 4.MyExtension()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment