Comment

Comment by batbomb

      There’s a consistency problem: the price may have
      changed  between the time that we received the order 
      and the time we looked up the product. To patch it up,
      we attach the product price to the order:

What you are describing is the lost update problem. This is solved in several ways. For example, an If-Unmodified-Since or If-Match header. In the first POST method, you had to get the product ID from somewhere, so you might have obtained a date or etag representing that product at a specific point in time.

When you POST the order, you could put the date of the last time you saw the price change in a header (or in the JSON itself, if you post multiple products). If the price changed, the server could respond with a 412 - Precondition failed. If you want to post a collection of items, maybe you could use If-Match. If you want to enforce this, you could return a 428 if the client didn't include some sort of preconditions.

http://tools.ietf.org/html/rfc6585#section-3

REST doesn't mean "Never user Headers".

parent batbomb 12 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton