Skip to content

Commit 8c832a7

Browse files
committed
Ping function | HttpRequestExtension
1 parent 3724409 commit 8c832a7

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.AspNetCore.Http;
2+
using System.IO;
3+
using System.Text;
4+
5+
namespace AzureDevOpsStateTracker.Functions.Extensions
6+
{
7+
public static class HttpRequestExtensions
8+
{
9+
public static string ObterCorpo(this HttpRequest request)
10+
{
11+
string corpo;
12+
using (StreamReader reader = new StreamReader(request.Body,
13+
encoding: Encoding.UTF8,
14+
detectEncodingFromByteOrderMarks: false,
15+
leaveOpen: true))
16+
{
17+
corpo = reader.ReadToEndAsync().Result;
18+
request.Body.Position = 0;
19+
}
20+
21+
return corpo;
22+
}
23+
24+
}
25+
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42

53
namespace AzureDevOpsStateTracker.Functions
6-
{
4+
{
75
public class ServiceToInject
86
{
97
public void DoSomething()
108
{
119
Console.WriteLine("Ok! Dependency Injection resolved!");
1210
}
1311
}
14-
}
12+
}

AzureDevOpsStateTracker.Functions/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
33
using Microsoft.Extensions.DependencyInjection;
44

5-
[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]
5+
[assembly: FunctionsStartup(typeof(Startup))]
66

7-
namespace MyNamespace
7+
namespace AzureDevOpsStateTracker.Functions
88
{
99
public class Startup : FunctionsStartup
1010
{

AzureDevOpsStateTracker.Functions/WorkItemFunctions.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using System;
2-
using System.IO;
3-
using System.Threading.Tasks;
41
using Microsoft.AspNetCore.Mvc;
52
using Microsoft.Azure.WebJobs;
63
using Microsoft.Azure.WebJobs.Extensions.Http;
74
using Microsoft.AspNetCore.Http;
85
using Microsoft.Extensions.Logging;
9-
using Newtonsoft.Json;
106

117
namespace AzureDevOpsStateTracker.Functions
128
{
@@ -26,7 +22,15 @@ public IActionResult Run(
2622
{
2723
_serviceToInject.DoSomething();
2824

29-
return new OkObjectResult("Ok");
25+
return new OkObjectResult("Ok - Run");
26+
}
27+
28+
[FunctionName("ping")]
29+
public IActionResult Ping(
30+
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
31+
ILogger log)
32+
{
33+
return new OkObjectResult("Ok - Ping");
3034
}
3135
}
32-
}
36+
}

0 commit comments

Comments
 (0)