How to send partial data to server for Update operation


#1

Assume i have assigned the following json as a model for a view.

“student”:{ “name”:“Christy”, “age”:“25”, “dob”:“05-06-1988” }

Let say user modifies name only. I want to send student data with name only in this case to the server i.e., partial update. I am not using Ember-data. how to achieve this.


#2

If you’re not using Ember-Data, then how you do it is completely up to you. You’re writing the server and client code, so you can do anything you want. However, a good starting point for the API is the JSON API. Here’s how they do PATCH updates.


#3

Also perhaps consider ember-orbit and orbit.js which has a JSONAPISource using JSON Patch for updates.


#4

JSON API is helpful to design API. My question is how to find the diff to decide what are the data changed so that i can send PATCH request with modified data.


#5

The model class has the changedAttributes method for that.


#6

Thanks for the reply. But i am not going to use Ember-Data due to its frequent changes.


#7

I don’t understand what you’re asking then. You’ve not using Ember-Data (or likely any of its alternatives), which means that you must have designed your own ad-hoc object model for persistence. Why are you asking us how to work with your object model?


#8

does anyone know of a method that is similar to changedAttributes for relationships. For a PATCH request I am updating a single attribute, and don’t want to send the rest of the attributes or the relationships to the server. In fact if they’ve updated I’d rather they become the source of truth so I really don’t want to send them. Is there an Ember Data way of doing this?