From b9b71c60a01fb3862aff7ea4735dd407202aa200 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 6 May 2022 13:27:40 -0700 Subject: [PATCH] Update Program.cs (#643) * Update Program.cs Use model binding * Update Program.cs --- .../csharp/http/order-processor/Program.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/service_invocation/csharp/http/order-processor/Program.cs b/service_invocation/csharp/http/order-processor/Program.cs index 1043572d..76b00bea 100644 --- a/service_invocation/csharp/http/order-processor/Program.cs +++ b/service_invocation/csharp/http/order-processor/Program.cs @@ -1,17 +1,18 @@ -using System.Text.Json.Serialization; - var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); -if (app.Environment.IsDevelopment()) {app.UseDeveloperExceptionPage();} +if (app.Environment.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); +} -app.MapPost("/orders", async context => { - var data = await context.Request.ReadFromJsonAsync(); - Console.WriteLine("Order received : " + data); - await context.Response.WriteAsync(data.ToString()); +app.MapPost("/orders", (Order order) => +{ + Console.WriteLine("Order received : " + order); + return order.ToString(); }); await app.RunAsync(); -public record Order([property: JsonPropertyName("orderId")] int orderId); +public record Order(int orderId);