In Web Api 2 I can return a 200 in two ways.
return Ok() or return Ok("Some value")
Or
return Content(HttpStatusCode.OK, "Some value") this can have any value included, along with formatters and some other parameters.
I know that return Content(...) supports all HttpStatusCodes so it will be used for responses like NoContent where there is no return NoContent()
Is return Ok() just a shortcut for return Content(..)?
Is
return Ok()just a shortcut forreturn Content(..)?
No
If you look at the methods in question you will see what they return IHttpActionResult derived classes
protected internal virtual NegotiatedContentResult<T> Content<T>(HttpStatusCode statusCode, T value);
protected internal FormattedContentResult<T> Content<T>(HttpStatusCode statusCode, T value, MediaTypeFormatter formatter);
protected internal virtual FormattedContentResult<T> Content<T>(HttpStatusCode statusCode, T value, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType);
protected internal FormattedContentResult<T> Content<T>(HttpStatusCode statusCode, T value, MediaTypeFormatter formatter, string mediaType);
protected internal virtual OkResult Ok();
protected internal virtual OkNegotiatedContentResult<T> Ok<T>(T content);
Each one of the return types are unrelated to each other except for the fact that they are derived from IHttpActionResult.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With