When is it appropriate to respond with a HTTP 412 error?

If you look at RFC 2616 you’ll see a number of request headers that can be used to apply conditions to a request:


These headers contain ‘preconditions’, allowing the client to tell the server to only complete the request if certain conditions are met. For example, you use a PUT request to update the state of a resource, but you only want the PUT to be actioned if the resource has not been modified by someone else since your most recent GET.

The response status code 412 (Precondition Failed) is typically used when these preconditions fail.

Your example sounds like an invalid request (i.e. the client has submitted data that is invalid because of missing values). A status code of 400 (Bad Request) is more appropriate here IMO.

Leave a Comment