Vadim Tabakman

Creating a Nintex Workflow Cloud Xtension using a C# Azure Function

This is a little addendum to the previous post : http://vadimtabakman.com/creating-a-nintex-workflow-cloud-xtension-using-a-javascript-azure-function.aspx

Since I've done a lot more C# dev than Javascript, I started looking into how to built an Azure Function using C#.

Below is one such function that does a Trigonometry Sin calculation.

The idea is to show how pass in information from a Query String or Body, use that to then do a Calculation and return the result that will eventually come out as JSON, with "result" being the key name.

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 angle = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "angle", true) == 0)
        .Value;

    // Get request body
    dynamic data = await req.Content.ReadAsAsync<object>();

    // Set name to query string or body data
    angle = angle ?? data?.angle;

    return angle == null
        ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a angle on the query string or in the request body")
        : req.CreateResponse(HttpStatusCode.OK, "{ \"result\": \"" + Math.Sin(Convert.ToDouble(angle)) + "\"}");
}

Posted by Vadim Tabakman Thursday, August 3, 2017 1:58:00 PM Categories: Azure Function Nintex Nintex Workflow Nintex Workflow Cloud
Copyright Vadim Tabakman
Rate this Content 0 Votes

Comments

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register





 

Statistics

  • Entries (249)
  • Comments (1729)

Categories