I'm really confused about the most appropriate way to return responses for my RESTful API that I'm building using Web API 2.
At first I made my actions return IHttpActionResult and in the method I would use return Ok() or return NotFound() etc.
Then I found there was no Forbidden() so I thought I must be doing things wrong. So now I'm making my actions return HttpResponseMessage. In my code I'm returning a response by doing the following:
HttpResponseMessage response = Request.CreateResponse();
response.StatusCode = HttpStatusCode.OK;
response.Content = new StringContent(JsonConvert.SerializeObject(responseData));
return response;
The problem is, this response now gets sent with the Content-Type "text/plain" - it needs to be sent with the Content-Type of "application/json". I can't find how I'm supposed to alter the Content-Type of the response, but even if I could it seems cumbersome to do this with every request. Is the a better way, some sort of best practice that I'm overlooking here?