fabric8-services / fabric8-wit

wit stands for Work Item Tracker
http://devdoc.almighty.io/
Apache License 2.0
45 stars 86 forks source link

Move usage of optimistic locking 'version' out of payload #155

Open aslakknutsen opened 8 years ago

aslakknutsen commented 8 years ago

Optimistic locking semantics are already built into the HTTP protocol.

Return ETag header on GET

Request:

GET /api/workitems/12

Response

200
Content-Type: application/json
ETag: "0"

{ "fields": {...}}

Update object with correct v

Request:

PUT /api/workitems/12
If-Match: "0"

{ "fields": {...}}

Response

200
Content-Type: application/json
ETag: "1"

{ "fields": {...}}

Update object with wrong v

Request:

PUT /api/workitems/12
If-Match: "0"

{ "fields": {...}}

Response

412 Precondition Failed
Content-Type: application/json

Only get body if ETag has changed

Request:

GET /api/workitems/12
If-Non-Match: "0"

Response

200
Content-Type: application/json
ETag: "1"

{ "fields": {...}}

Don't return body if ETag match

Request:

GET /api/workitems/12
If-Non-Match: "1"

Response

304
Content-Type: application/json
baijum commented 8 years ago

I have edited the description to use workitems in the URL end points.