-
Notifications
You must be signed in to change notification settings - Fork 1
/
AzureFunctionV2.cs
31 lines (27 loc) · 1012 Bytes
/
AzureFunctionV2.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
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
namespace AzureFunctionV2Example
{
public class AzureFunctionV2
{
private readonly IGreetingsService _greetingsService;
public AzureFunctionV2(IGreetingsService greetingsService)
{
_greetingsService = greetingsService;
}
[FunctionName("SayHello")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
string name = req.Query["name"];
return !string.IsNullOrWhiteSpace(name)
? (ActionResult)new OkObjectResult(_greetingsService.SayHi(name))
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
}
}