How can I prevent Ext JS from including an entity body in DELETE requests using a restful store?

后端 未结 2 1422
醉梦人生
醉梦人生 2021-01-18 11:12

When Ext JS issues a DELETE request from a restful store, it includes an entity body. Although this doesn\'t seem to be forbidden by the HTTP spec, Google App Engine doesn\'

相关标签:
2条回答
  • 2021-01-18 11:27

    You can fix this problem, as you guessed, by overriding a method in the HttpProxy class. First, add this code:

    // Special HttpProxy that sends no body on DELETE requests
    Ext.data.GAEHttpProxy = Ext.extend(Ext.data.HttpProxy, {
    doRequest: function(action, rs, params, reader, cb, scope, arg) {
        if(this.api[action]['method'].toLowerCase() == "delete") {
            delete params.jsonData;
        }
    
        Ext.data.GAEHttpProxy.superclass.doRequest.call(this, action, rs, params, reader, cb, scope, arg);
    }
    });
    

    Then, use this new class ("GAEHttpProxy") instead of HttpProxy in the rest of your code (for instance, when you create the proxy you use in your store shown above). This worked for me, and I hope it works for you!

    0 讨论(0)
  • 2021-01-18 11:40

    Although the question is asked 7 years ago and we have sencha 6 now, the problem isn't solved OOTB yet. So here is my working solution:

    Ext.define('My.Proxy', {
        extend: 'Ext.data.proxy.Rest',
        writer: {
            type: 'json',
            writeAllFields: true, // may be false, as you wish
            transform: {
                fn: function(data, request) {
                    return request.config.action === 'destroy' ? null : data;
                },
                scope: this
            }
        }
    });
    

    We could also do this check: request.config.method === 'DELETE' but for some reason it always returns false. So I recommend to stay with action === 'destroy'

    0 讨论(0)
提交回复
热议问题