What HttpNoContentOutputFormatter Do?
In DotNet Core Web API by default configured with HttpNoContentOutFormatter. When a NULL result is passed to the 'OK()' method in API, the client consuming that API receives status code 204(NO Content Found) without any response, instead of status code 200 with response NULL value.
Sample API endpoint:(returns the NULL result)
[Route("Test")] [HttpGet] public IActionResult Test() { string result = null; return Ok(result);}
API Result:
Returning status 204 is an ideal response for NULL results. But if you want to receive a NULL response with status 200 we can do by removing this HttpNoContentOutputFormatter.
Startup.cs:(ConfigureServices method):
services.AddControllers(options => { options.OutputFormatters.RemoveType<HttpNoContentOutputFormatter>();});
Comments
Post a Comment