Skip to content

Instantly share code, notes, and snippets.

@itn3000
Created April 6, 2016 01:17
Show Gist options
  • Save itn3000/e9b4d05b426821c30842c3ffb1121f47 to your computer and use it in GitHub Desktop.
Save itn3000/e9b4d05b426821c30842c3ffb1121f47 to your computer and use it in GitHub Desktop.
extension method in Azure Functions
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