PDA

View Full Version : Proxy REST



sj_tt6
13 May 2012, 7:22 AM
Hi,

I have a problem with proxy REST. My app has a grid panel to display a list of account's ids and a form to show data of the account of which the id is selected in the grid panel. I define a data model for the grid panel and in there I have a proxy like below


proxy: {
type: 'rest',
api: {
create : 'crud',
read : 'crud',
update : 'crud',
destroy : 'crud'
},
reader: {
type: 'json',
root: 'results'
},
writer: {
type: 'json'
}
}

In the backend I have REST methods to serve GET, POST, PUT, and DELETE
I don't have problems with loading, updating, and deleting records by calling corresponding functions on data model like save, destroy. However when I create a new record from the form, I try with create, add... They don't work (of course according to data model API). I look into Ext.data.proxy.Rest API and try my codes like the sample but it always send PUT method instead of POST.
In the meantime I have to call save on the my data model to create a new record in the backend.

Update records:


var form = formPanel.getForm();
var record = form.getRecord();
var vals = form.getValues();
record.set(vals);
record.save({ // send PUT to the backend to update
....
});
...



Create new record:


var form = formPanel.getForm();
var vals = form.getValues();
var new_rec = Ext.create(Myapp.model.Key', vals);

new_rec.save({ // send POST to the backend to add
....
});
...


What function should I call when creating a new record to send a POST method to the backend?

Thank you,

scottmartin
14 May 2012, 8:20 AM
Have a look at:



proxy: {
type: 'rest',
url: 'server.php',
// actionMethods: 'POST', // overrides all
actionMethods: {
read: 'GET',
create: 'POST',
update: 'PUT', // override single
destroy: 'DELETE'
},
appendId: false,
reader: {
type: 'json',
root: 'data',
totalProperty: 'total'
}
}


Regards,
Scott.

sj_tt6
14 May 2012, 4:30 PM
Hi Scott,

I tried your settings but the request is still PUT when I created a new record.

scottmartin
14 May 2012, 4:42 PM
Place 'POST' in update.

Scott.