Giải thích về JSON Binding?
Giải thích về JSON Binding?
JSON Binding là việc ASP.NET Core ánh xạ JSON trong request body thành đối tượng C# (deserialize) và ngược lại cho response, thực hiện bởi input/ output formatter.
public record CreateUser(string Name, string Email, int Age);
[HttpPost]
public IActionResult Create([FromBody] CreateUser dto) // [ApiController] tự bind từ body + validate
{
return CreatedAtAction(nameof(Get), new { id = 1 }, dto);
}
// Minimal API
app.MapPost("/users", (CreateUser dto) => TypedResults.Created($"/users/1", dto));
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.