Skip to Content
RESTful Web Services Cookbook
book

RESTful Web Services Cookbook

by Subbu Allamaraju
March 2010
Intermediate to advanced
312 pages
7h 31m
English
O'Reilly Media, Inc.
Content preview from RESTful Web Services Cookbook

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. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

RESTful Web Services

RESTful Web Services

Leonard Richardson, Sam Ruby
RESTful Web Clients

RESTful Web Clients

Mike Amundsen

Publisher Resources

ISBN: 9780596809140Errata Page