Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How do I return HttpStatus codes in ASP.NET Core 1.0 API?

$
0
0

I have an API method that returns an object. However, if I detect some issues, I want to be able to return a certain Http status code. What's the right way to handle this in the new ASP.NET Core 1.0 API?

Here's my code:

[HttpPost]
public async Task<SomeObject> Post([FromBody] value)
{
   if(value == null)
      // I want to return HttpBadRequest code here.

   // Some logic
   return myObject;
}

Returning HttpStatus codes were pretty easy in the previous version of API. What's the right -- and hopefully even easier way -- in the new version?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>