我正在通过Loopback框架开发rest API。当有人使用远程方法向模型发送Temp Time
22 2015-11-17 14:00:00
23 2015-11-17 15:00:00
23 2015-11-17 16:00:00
22.05 2015-11-17 17:00:00
请求时,我想转储传入的请求。即使密钥与 arg ,POST
中的指定名称不匹配,我也希望这样做。因此,基本上在控制台中打印argument
请求,无论它包含什么,例如PHP中的POST
。
var_dump($_POST)
感谢。
答案 0 :(得分:1)
您可以使远程方法接受object
类型。这将使它接受任何类型的论证。然后,您可以使用loopback的getCurrentContext()
函数来获取context
对象并解析request
对象,如下所示。
var loopback = require('loopback');
module.exports = function(YourModel) {
...
//remote method
YourModel.someMethod = function(argument, cb) {
var ctx = loopback.getCurrentContext();
var postRequest = ctx && ctx.req;
console.log(postRequest); //here's your POST request
...
cb(null, "done");
};
someMethod.remoteMethod(
'pickTrans',
{
accepts: {arg: 'argument', type: 'object', http: {source: 'body'}},
http: {
path: '/pickTrans',
type: 'post'
},
returns: {arg: 'response', type:'string'}
}
);
...
};
希望这能解决你想要达到的目标。