I am using ASP.NET Web Api and one of the methods is exposed as a POST operation. It works fine, but it returns a HTTP Result of 204 instead of 201 as expected. Here is the method definition:
[HttpPost][ActionName("Save")]
public Task SaveGameState(Guid instanceId, [FromBody] ComparisonGameState state)
{
return gameInstancesClient.SaveGameState(instanceId, state);
}
Is the fact that it is returning a Task confusing Web Api?
I could do the following instead, but it seems like overkill:
[HttpPost][ActionName("Save")]
public async Task<HttpResponseMessage> SaveGameState(Guid instanceId, [FromBody] ComparisonGameState state)
{
await gameInstancesClient.SaveGameState(instanceId, state);
return new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.Created };
}
Thank you!
Barring further input, this seems to be the only workable solution: