Skip to content

Commit f4e1364

Browse files
committed
chore: add HttpJsonBodyParser Middleware Sample
1 parent 3914bd0 commit f4e1364

File tree

8 files changed

+139
-1
lines changed

8 files changed

+139
-1
lines changed

Voxel.MiddyNet.sln

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Voxel.MiddyNet.ApiGatewayPr
7979
EndProject
8080
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Voxel.MiddyNet.HttpJsonBodyParserMiddleware.Tests", "test\Voxel.MiddyNet.HttpJsonBodyParserMiddleware.Tests\Voxel.MiddyNet.HttpJsonBodyParserMiddleware.Tests.csproj", "{AD9A0773-EF96-4F4A-890C-337277EDCC2F}"
8181
EndProject
82-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Voxel.MiddyNet.HttpJsonBodyParserMiddleware", "src\Voxel.MiddyNet.HttpJsonBodyParserMiddleware\Voxel.MiddyNet.HttpJsonBodyParserMiddleware.csproj", "{111CB170-E682-498D-9E84-42FFFB66CE36}"
82+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Voxel.MiddyNet.HttpJsonBodyParserMiddleware", "src\Voxel.MiddyNet.HttpJsonBodyParserMiddleware\Voxel.MiddyNet.HttpJsonBodyParserMiddleware.csproj", "{111CB170-E682-498D-9E84-42FFFB66CE36}"
83+
EndProject
84+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpJsonBodyParser", "HttpJsonBodyParser", "{2B9304CC-B4DD-4DD5-9428-F7D8A0BC39BC}"
85+
EndProject
86+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Voxel.MiddyNet.HttpJsonBodyParserSample", "samples\HttpJsonBodyParser\Voxel.MiddyNet.HttpJsonBodyParserSample\Voxel.MiddyNet.HttpJsonBodyParserSample.csproj", "{3E45575F-C260-41FD-B5C9-3D675E5BD0C9}"
8387
EndProject
8488
Global
8589
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -203,6 +207,14 @@ Global
203207
{111CB170-E682-498D-9E84-42FFFB66CE36}.Debug|Any CPU.Build.0 = Debug|Any CPU
204208
{111CB170-E682-498D-9E84-42FFFB66CE36}.Release|Any CPU.ActiveCfg = Release|Any CPU
205209
{111CB170-E682-498D-9E84-42FFFB66CE36}.Release|Any CPU.Build.0 = Release|Any CPU
210+
{3E45575F-C260-41FD-B5C9-3D675E5BD0C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
211+
{3E45575F-C260-41FD-B5C9-3D675E5BD0C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
212+
{3E45575F-C260-41FD-B5C9-3D675E5BD0C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
213+
{3E45575F-C260-41FD-B5C9-3D675E5BD0C9}.Release|Any CPU.Build.0 = Release|Any CPU
214+
{3445910D-DFEB-45F9-8CCC-702129267C4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
215+
{3445910D-DFEB-45F9-8CCC-702129267C4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
216+
{3445910D-DFEB-45F9-8CCC-702129267C4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
217+
{3445910D-DFEB-45F9-8CCC-702129267C4D}.Release|Any CPU.Build.0 = Release|Any CPU
206218
EndGlobalSection
207219
GlobalSection(SolutionProperties) = preSolution
208220
HideSolutionNode = FALSE
@@ -242,6 +254,9 @@ Global
242254
{615A99CC-A3ED-4E42-9A9A-AC29B13B095C} = {1F42DBC9-C1FC-4FC7-A5A0-97B47C410C26}
243255
{AD9A0773-EF96-4F4A-890C-337277EDCC2F} = {202D1DF0-62D6-4006-99DC-BBFBE59428B1}
244256
{111CB170-E682-498D-9E84-42FFFB66CE36} = {202D1DF0-62D6-4006-99DC-BBFBE59428B1}
257+
{2B9304CC-B4DD-4DD5-9428-F7D8A0BC39BC} = {B07FEFF7-B407-4792-8C6B-B6D0CC8626D4}
258+
{3E45575F-C260-41FD-B5C9-3D675E5BD0C9} = {2B9304CC-B4DD-4DD5-9428-F7D8A0BC39BC}
259+
{3445910D-DFEB-45F9-8CCC-702129267C4D} = {B07FEFF7-B407-4792-8C6B-B6D0CC8626D4}
245260
EndGlobalSection
246261
GlobalSection(ExtensibilityGlobals) = postSolution
247262
SolutionGuid = {EFA347F5-761B-44CF-B6DB-8981387C72B3}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Threading.Tasks;
2+
using Amazon.Lambda.Core;
3+
using Amazon.Lambda.APIGatewayEvents;
4+
using Voxel.MiddyNet.HttpJsonBodyParserMiddleware;
5+
6+
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
7+
namespace Voxel.MiddyNet.HttpJsonBodyParserSample
8+
{
9+
public class HttpJsonBodyParser : MiddyNet<APIGatewayProxyRequest, APIGatewayProxyResponse>
10+
{
11+
public HttpJsonBodyParser()
12+
{
13+
Use(new HttpJsonBodyParserMiddleware<Person>());
14+
}
15+
16+
protected override Task<APIGatewayProxyResponse> Handle(APIGatewayProxyRequest lambdaEvent, MiddyNetContext context)
17+
{
18+
var person = ((Person) context.AdditionalContext["Body"]);
19+
context.Logger.Log(LogLevel.Info, "Function called", new LogProperty("body", person));
20+
var result = new APIGatewayProxyResponse
21+
{
22+
StatusCode = 200,
23+
Body = $"Person name is {person.Name} {person.Surname} and it is {person.Age} years old."
24+
};
25+
26+
return Task.FromResult(result);
27+
}
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace Voxel.MiddyNet.HttpJsonBodyParserSample
4+
{
5+
public class Person
6+
{
7+
[JsonPropertyName("name")]
8+
public string Name { get; set; }
9+
[JsonPropertyName("surname")]
10+
public string Surname { get; set; }
11+
[JsonPropertyName("age")]
12+
public int Age { get; set; }
13+
14+
}
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
6+
<AssemblyName>Voxel.MiddyNet.HttpJsonBodyParserSample</AssemblyName>
7+
<PackageId>Voxel.MiddyNet.HttpJsonBodyParserSample</PackageId>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Amazon.Lambda.Core" Version="1.2.0" />
12+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.1.0" />
13+
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.4.0" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\..\src\Voxel.MiddyNet.HttpJsonBodyParserMiddleware\Voxel.MiddyNet.HttpJsonBodyParserMiddleware.csproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dotnet restore
2+
dotnet tool install -g Amazon.Lambda.Tools --framework netcoreapp3.1
3+
dotnet build --configuration Release
4+
dotnet lambda package --configuration Release --framework netcoreapp3.1 --output-package bin/Release/netcoreapp3.1/Voxel.MiddyNet.HttpJsonBodyParserSample.zip
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
#install zip on debian OS, since microsoft/dotnet container doesn't have zip by default
4+
if [ -f /etc/debian_version ]
5+
then
6+
apt -qq update
7+
apt -qq -y install zip
8+
fi
9+
10+
dotnet restore
11+
dotnet tool install -g Amazon.Lambda.Tools --framework netcoreapp3.1
12+
dotnet build --configuration Release
13+
dotnet lambda package --configuration Release --framework netcoreapp3.1 --output-package bin/Release/netcoreapp3.1/Voxel.MiddyNet.HttpJsonBodyParserSample.zip
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
service: voxel-middynet-httpJsonBodyParserSample
2+
3+
provider:
4+
name: aws
5+
runtime: dotnetcore3.1
6+
region: ${opt:region, self:custom.defaultRegion}
7+
stage: ${opt:stage, self:custom.defaultStage}
8+
9+
custom:
10+
defaultRegion: eu-west-1
11+
defaultStage: dev${env:SLSUSER, ""}
12+
sqsTracingSampleQueueName: ${self:service}-${self:provider.stage}-httpJsonBodyParserSample
13+
package:
14+
individually: true
15+
16+
functions:
17+
httpJsonParserSample:
18+
handler: Voxel.MiddyNet.HttpJsonBodyParserSample::Voxel.MiddyNet.HttpJsonBodyParserSample.HttpJsonBodyParser::Handler
19+
package:
20+
artifact: bin/Release/netcoreapp3.1/Voxel.MiddyNet.HttpJsonBodyParserSample.zip
21+
events:
22+
- http: POST testParser
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
6+
<AssemblyName>Voxel.MiddyNet.HttpJsonBodyParserSample</AssemblyName>
7+
<PackageId>Voxel.MiddyNet.HttpCorsSample</PackageId>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Amazon.Lambda.Core" Version="1.2.0" />
12+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.1.0" />
13+
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.4.0" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\src\Voxel.MiddyNet.HttpJsonBodyParserMiddleware\Voxel.MiddyNet.HttpJsonBodyParserMiddleware.csproj" />
18+
</ItemGroup>
19+
20+
</Project>

0 commit comments

Comments
 (0)