rich remer
rich remer

Reputation: 3577

HTTP response status for missing if-match header

I have a REST-ful service which is using ETags and If-Match headers to control updates.

If a client submits a conditional request with an If-Match header, and the ETag is stale, I am returning a 412 Precondition Failed, which appears to be the recommended approach to an ETag mismatch.

But what if the client submits without an If-* header? My understanding of 412 is that it applies to Client preconditions. Since the client did not submit an If-Match header, there are no client preconditions. But if I want to require If-Match, what response should I use?

My thinking so far is maybe 400 Bad Request or 409 Conflict. Are there any best practices?

Upvotes: 1

Views: 2345

Answers (1)

Thierry Templier
Thierry Templier

Reputation: 202156

I think that the code 400 is a bit general but can apply. In such case, you need to provide more details about the problem within the response content.

IMO, code 409 should be used if there is a conflict with the current state of the resource. I think that it's more in the case where you implement optimitic locking by yourself without using headers ETag and If-*.

I saw a code 428 (Precondition Required) that seems to correspond to your needs.

The following page could give you more details: http://www.restapitutorial.com/httpstatuscodes.html.

Hope it helps you, Thierry

Upvotes: 2

Related Questions