Skip to content

PATCH request should be atomic #20

@risseraka

Description

@risseraka

Per HTTP PATCH spec

 Note that the HTTP PATCH method is atomic, as per [RFC5789].
   Therefore, the following patch would result in no changes being made
   to the document at all (because the "test" operation results in an
   error):

   [
     { "op": "replace", "path": "/a/b/c", "value": 42 },
     { "op": "test", "path": "/a/b/c", "value": "C" }
   ]

Ref: http://tools.ietf.org/html/rfc6902#section-5

In other words, none of a patch's operations should be applied if any one of them fails.

> var obj = {};
undefined

> jsonpatch.apply(obj, [
  {op: 'add', path: '/foo', value: 'bar'}, 
  {op: 'remove', path: '/baz'}
]);
PatchConflictError: Value at baz does not exist // OK

> obj
{ foo: 'bar' }  // NOT OK

jsonpatch.apply should perhaps test every operations before applying them.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions