-
Notifications
You must be signed in to change notification settings - Fork 4
/
TestFunction.cs
34 lines (30 loc) · 1.09 KB
/
TestFunction.cs
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
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;
using System.IO;
namespace RedisFunctionSample
{
public static class TestFunction
{
[FunctionName("Test")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "GET", Route = "test")] HttpRequest req,
TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
using (var reader = new StreamReader(req.Body))
{
string requestBody = reader.ReadToEnd();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
}
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
}
}