-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSampleAzureFunctionAppDotNet.cs
More file actions
48 lines (40 loc) · 1.6 KB
/
Copy pathSampleAzureFunctionAppDotNet.cs
File metadata and controls
48 lines (40 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
namespace FunctionApp5
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "hello/{name:alpha}")]HttpRequestMessage req, string name, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
if (name == null)
{
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
name = data?.name;
}
//return (ActionResult)new OkObjectResult("Hello " + name);
//return (a)
//return name;
var response = req.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent("Hello " + name, Encoding.UTF8, "text/plain");
return response;
//return response;
//return req.CreateResponse(HttpStatusCode.OK, "Hello " + 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);
}
}
}
-------------------------
from browser Call -- https://kumar.azurewebsites.net/api/hello/kumar
returns : Hello kumar