mirror of https://github.com/dapr/quickstarts.git
Update Program.cs (#643)
* Update Program.cs Use model binding * Update Program.cs
This commit is contained in:
parent
57fc9655cb
commit
b9b71c60a0
|
|
@ -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<Order>();
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue