totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

Body request in DELETE method is empty #731

Closed aalfiann closed 5 years ago

aalfiann commented 5 years ago

My question is how to get body request value when using DELETE method?

controller

exports.install = function() {
    ROUTE('/api/user/delete', ['delete','*User --> @delete']);
};

schema

NEWSCHEMA('User').make(function(schema) {
  schema.define('id', 'string');
  schema.addWorkflow('delete', function($) {
    console.log($.model);
  });
});

cURL

curl -X DELETE \
  http://127.0.0.1:8000/api/user/delete \
  -H 'Content-Type: application/json' \
  -H 'Host: 127.0.0.1:8000' \
  -H 'cache-control: no-cache' \
  -d '{
    "id":"5d88af3e45df0a0e376e6724"
}'

console.log Why the id is empty?

SchemaInstance { id: '' }
petersirka commented 5 years ago

Hi @aalfiann, preparing of data is disabled in DELETE method. You can get raw data via $.body property. It's because in most cases you send only id of record for deleting some records. Therefore Total.js disables validation.

aalfiann commented 5 years ago

Yeah, in most cases only need id record for deleting the data. But in our project there is 3 conditions required and it's too long if I just put it in url.

Btw, $.body is work.

Thank you very much.