I have created simple azure Function (Http+C#) which returns simple test.I want to return response from azure functions to azure mobile services.Before i have invoked stored procedure from my mobile services.now i am trying to invoke that azure function(node Js) want to get back the response from azure functions. Azure mobile Service Code and my simple azure function script below
module.exports = {
"post": function (req, res, next) {
console.log("Started Application Running");
var http = require("http");
var options = {
host: "< appname >.azurewebsites.net",
path: "api/<functionname>?code=<APIkey>",
method: "POST",
headers : {
"Content-Type":"application/json",
"Content-Length": { name : "Testing application"}
}
};
http.request(options, function(response) {
var str = "";
response.on("data", function (chunk) {
str += chunk;
res.json(response);
console.log("Something Happens");
});
response.on("end", function () {
console.log(str);
res.json(response);
});
});
console.log("*** Sending name and address in body ***");
}
};
Here is my azure function
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;
string name = "divya";
// 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 Welcome ");
}
.Can any one help me?