Void method call results for PUT and POST

Topics: ASP.NET Web API
Apr 12, 2012 at 9:29 PM

When you have a void action method:

public void Put(Order payload)


public void Post(Order payload)

By specifying a void return, shouldn't the default status code be 204? Or any action method for that matter. Right now it's 200, with empty content.


Apr 12, 2012 at 9:40 PM

+1. OData does 204, for void Actions.

Apr 12, 2012 at 10:33 PM

This sounds like a good idea. Methods returning void or Task could easily have a status code of 204 instead of 200. This would be a 1-line change in the source.

One thing to note here is that filters and message handlers need to be aware of this behavior and do the right thing to avoid having a response with content and a 204 status. But that's general guidance the applies not just to this situation.

Apr 13, 2012 at 2:36 PM

Pull request here:


The NoContentOnNoReturn branch.

Jun 1, 2012 at 2:31 AM
Edited Jun 1, 2012 at 2:31 AM

XmlHttpRequest in internet explorer throws an "operation aborted" exception if you return 204.


Worked around in jquery, but considering this bug exists in internet explorer, it may not be worth returning the correct status code if it causes other issues down the road. The workaround jquery uses drops all response headers