I'm experimenting with converting some simple controller methods to using endpoint routing on the latest RC of aspnet core 6. The controller works fine, and it looks like this:
[HttpPost]
public async Task<IActionResult> CreateUser(NewUserRequest newUser)
{
/* do stuff with newUser */
/* return CreatedAtRoute(...); */
}
I've tried converting to using IEndpointRouteBuilder, like so:
endpoints.MapPost("/api/user/test",
(NewUserRequest request) =>
{
/* same thing as controller method */
});
// prints error to the log:
// Implicit body inferred for parameter "request" but no body was provided. Did you mean to use a Service instead?
I'm using the exact same test request (through Postman, usually), so I know it's not the client's problem. What's more, if I just take an HttpRequest parameter, I can read the body into a json blob.
endpoints.MapPost("api/user/test2",
async (HttpRequest request) =>
{
using (var sr = new StreamReader(request.BodyReader.AsStream()))
{
var body = await sr.ReadToEndAsync();
/* body is valid json here */
}
});
I'm really at a loss here, especially since it works in some cases, but not when I'm binding a type to one of the minimal endpoints.