I've been using my own implementation of server-side feeders (Direct-like) for ExtJS stores for a long time since version 2, and thus I customized Store and HttpProxy in previous versions. Now I am learning the data concepts of version 4 and have started customizing AjaxProxy to get it communicate with my server-side code.
Basically, there would be just three customizations:
- All actions, including read are requested via POST method, and
- All requests are made to the same URL, and
- All requests send JSON payload instead of POST fields, thus I need to use request.jsonData instead of request.params.
The inconvenience is, on order to replace params with jsonData, I have to override the whole doRequest method, where the difference is just in two lines: setting request.jsonData and deleting request.params. So, the proxy would look like this:
Code:
Ext.define('Ext.data.MyProxy', {
extend: 'Ext.data.AjaxProxy',
alias: 'proxy.my',
doRequest: function(operation, callback, scope) {
var writer = this.getWriter(),
request = this.buildRequest(operation, callback, scope);
if (operation.allowWrite()) {
request = writer.write(request);
}
Ext.apply(request, {
headers : this.headers,
timeout : this.timeout,
jsonData : request.params,
scope : this,
callback : this.createRequestCallback(request, operation, callback, scope),
method : this.getMethod(request),
disableCaching: false // explicitly set it to false, ServerProxy handles caching
});
delete request.params;
Ext.Ajax.request(request);
return request;
},
constructor: function() {
Ext.data.MyProxy.superclass.constructor.apply(this, arguments);
this.actionMethods.read = 'POST';
}
});
Is there any more simple and elegant solution to achieve my goals? If not, would the team consider an option for AjaxProxy that would enable sending data in JSON payload instead of HTTP fields? Thanks in advance.