Chapter 10. Conditional Requests
Conditional requests in HTTP help address two problems. For
GET
requests, conditional requests help clients and caches
validate that a cached representation can still be considered fresh. For
unsafe requests such as PUT
, POST
, and
DELETE
, conditional requests provide concurrency
control.
Not supporting conditional GET
requests reduces
performance, but in the face of concurrency, not making unsafe requests
such as POST
, PUT
, and DELETE
conditional may affect the integrity of the application. In the absence of
adequate concurrency control checks, the server is susceptible to
“lost updates” and “stale deletes.” When a
client submits a request to modify or delete a resource, it does so based
on what it thinks is the current state of the resource. But under
concurrent conditions, the current state of the resource is not static.
Either the server, through some backend means, or other clients may have
updated or deleted the resource.
Concurrency control ensures the correct processing of data under concurrent operations by clients. There are two ways to implement concurrency control:
- Pessimistic concurrency control
In this model, the client gets a lock, obtains the current state of the resource, makes modifications, and then releases the lock. During this process, the server prevents other clients from acquiring a lock on the same resource. Relational databases operate in this manner.
- Optimistic concurrency control
In this model, the client first gets a token. ...
Get RESTful Web Services Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.