I came across this question while I was searching for something similar (but simpler): How to return plain text from a minimal WebApi in general? I am using .NET 8, and found that I can use the Results.Text() method like this:
app.MapGet("/HelloWorld", () =>
{
return Results.Text("Hello World!\nYou are looking good today.", "text/plain", Encoding.UTF8, 200);
});