I am trying to read the request body that was sent from client to my backend. The content is sent in JSON format and has users input from a form. How do I read the request body in a middleware that I set up for my controller Route.
Here is my Model
namespace ChatboxApi.Models
{
public class User
{
public string Login { get; set; } = default;
public string Password { get; set; } = default;
public string Email { get; set; } = default;
public string FullName { get; set; } = default;
public int Phone { get; set; } = default;
public string Website { get; set; } = default;
}
}
Here is my Controller
namespace ChatboxApi.Controllers
{
[ApiController]
[Route("api/signup")]
public class SignupController : ControllerBase
{
[HttpPost]
public ActionResult SignUp([FromBody] User user)
{
return Ok(user);
}
}
}
Here is my middleware class
namespace ChatboxApi.Middleware
{
public class CreateSession
{
private readonly RequestDelegate _next;
public CreateSession(RequestDelegate next)
{
this._next = next;
}
public async Task Invoke(HttpContext httpContext)
{
//I want to get the request body here and if possible
//map it to my user model and use the user model here.
}
}