I am setting up a new .net core webapi using v2.2. This has a simple get function which is supposed to return either the current date if the request is a heartbeat or a Json object.
I have set up the heartbeat function as a HTTPGet using an IActionResult return type. I have tried using both the Controllerbase class as well as the Controller class but am having the same issue no matter which I try
My controller class declaration is as follows:
public class TestController : ControllerBase
{
IConfiguration _iconfiguration;
public TestController(IConfiguration configuration)
{
_iconfiguration = configuration;
}
// GET: api/Interceptor
[HttpGet("Heartbeat")]
public IActionResult Get()
{
//Set the return DateTime for return value
string currentDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
return Ok(currentDateTime);
//return Ok("Heartbeat Message Received");
//return Ok(new { message = "Heartbeat Message Received: " + currentDateTime });
//var result = new OkObjectResult(new { message = "200 OK", currentDate = DateTime.Now });
//return result;
//return Ok(Json("123"));
//return new string[] { "value1", "value2" };
}
}
As you can see I have tried various methods to try and get a return string to be delivered back. When I do the call in Postman to this service, I get the 200Ok return status fine, however the body of my response (in this case the current date time) just comes back empty. return types tried:
- Ok(result)
- Ok(string)
- OkResultObject(object)
- string
- array
In all cases Postman returns me a status 200 Ok but no body.
Screenshot of what I see when I do a postman call
The IDE I am using is VS2017 Enterprise version 15.9.7
IActionResultall gone with the old MVC 5.2 and you should just return objects now? - zaitsman