Conditional Requests & Updates
The Sway Charts REST API relies on standard HTTP conditional update and request mechanism (http://en.wikipedia.org/wiki/HTTP_ETag) to ensure that:
No update is missed and client is always updating the latest resource version (conditional
PUTandDELETErequests).The client already has the latest version of the resource and there is no need to re-compute the representation again (conditional
GETrequests).
The Sway Charts REST API relies on the ETag/If-Match/If-None-Match HTTP headers for conditional requests.
Conditional GETs
Some GET requests to the REST API (except for collection queries) support conditions with the ETag headers according to the following algorithm:
Client makes a GET request to a resource without the
If-None-Matchheader.Server always returns a representation of the resource with an
ETagheader set. TheETagheader uniquely and transparently identifies the version of the resource.If a resource is updated, its version is incremented and previous
ETags are no longer valid.Client makes a
GETrequest to a resource specifying theIf-None-Matchheader with the value of previously receivedETag.If
ETagmatches the current version on the server, the server responds with the304 Not Modifiedstatus code and empty body. The server includes theETagheader to the response.If
ETagdoesn't match the current version on the server, the server responds with a new resource representation and includes the newETagheader in the response.
Conditional PUTs and DELETEs
All PUT and DELETE requests to the REST API must contain the ETag headers according to the following algorithm:
Client makes a GET request to a resource without the
If-None-Matchheader.Server always returns a representation of the resource with an
ETagheader set. TheETagheader shall uniquely identify the version of the resource.If a resource is updated, its version is incremented and previous
ETagsare no longer valid.Client makes a
PUTorDELETErequest to a resource specifying theIf-Matchheader with the value of previously receivedETag.If
ETagmatches the current version on the server, the server proceeds with the request.If
ETagdoesn't match the current version on the server, the server responds with the412 Precondition Failedstatus. Client is expected to retrieve the latest resource version and retry the request.If the client doesn't submit the
If-Matchheader, status code of403 Forbiddenis returned along with the error details.
This prohibits "stale update" problems when there are several simultaneous updates for the same resource and one update overrides the other.
Last updated