I'm trying to send a model to a REST service using save(), but I need to pass a header parameter along with the json data so that the correct service is invoked (spring can use the headers to route the call to the right handler). That is, I'm not really saving the model, I'm performing an specific action upon it (in this case, it's an approval action). The PUT url should look something like this:
http://server/name/1
And this shouldn't change because the resource identity isn't changing. But, the headers should include a header containing the action. In this case we'll call the parameter 'command', and this specific example the value of command is 'approve'.
I've tried adding an object with a data field to the save:
model.save({data: {command:'approve'}})
But that simply adds the object associated with the data to the json data in the body of the request. I've read that this approach works on the fetch side to add the given data as params, but on save it seems to not work according to my expectations. I've single stepped through the backbone code and if the data option exists on a save it is merged with the model.
As I have no control over the service interface I have to work out how to to set the header parameter. Can anyone give me some guidance as to how to achieve this at the point of saving the model?