Our site uses cookies. Learn more about their purpose and change of settings in a browser If you are using the site, you give you consent to use cookies, according to current browser settings. Got it

Generic JSON Patch service

  • Language JavaScript
Implement generic AngularJS service for generating JSON Patch requests based on model changes.

Patch Model Service


We need generic service for generating JSON Patch requests based on model changes.

An app provides API for listing and updating various objects. Each object type has it's own endpoint. We want to issue XHR requests to update backend on every model change. In order to avoid sending back and forth full objects we will only send JSON Patches.


Your goal is to implement the service that would watch for changes on given object and issue JSON Patch requests to the backend. Make the service as reusable as possible. For generating patches you can use https://www.npmjs.com/package/fast-json-patch. The service should be configurable like this:

patchModel(object, $scope).api('/api/endpoint').ignore(['/photo']);

or patchModel(object, $scope).api('/api/endpoint').ignore(['/photo']).id(object._id); or patchModel(object, $scope).callback(callback);

Which means that object will be watched as long as $scope is not destroyed. If there are any changes then JSON Patch should be created and sent to the backend to /api/endpoint/:id using PATCH HTTP method where :id is value of object.id. User may also provide id explicitly. Sometimes there is a need to ignore some properties, as they are being used only on the frontend and should not be saved to the backend. By default ignore $$hashKey property and if user wants to ignore others, let them specify that explicitely.

If callback is provided then instead of sending request to the backend the callback should be invoked with JSON Patch data.


For now there are two entities: attraction and note. Here is the API you might need to interact with in order to finish this task.

Update attraction

PATCH /api/attraction/:id {}

Update note

PATCH /api/note/:id {}

Please note that the API is mocked on the frontend, so if you reload browser window all posted data will be lost.


To install dependencies from package.json:

yarn install

To install dependencies from bower.json:

bower install

To run tests in development mode:

grunt test:dev

To run verify jshint, tests and coverage:

yarn test

To run verify jshint, tests and coverage with human readable output:

grunt --force

To start browser in live reload mode:

grunt serve

Start this test

I agree to subscription in accordance with the terms of service.
Go to the top and begin