我有以下模型,它应该使用来自post API的消息:
'use strict';
module.exports = function (Message) {
Message.hl7_message = function (cb) {
cb(null, 'Success... ');
}
Message.remoteMethod(
'hl7_message', {
http: {
path: '/hl7_message',
verb: 'post',
status: 200,
errorStatus: 400
},
accepts: [],
returns: {
arg: 'status',
type: 'string'
}
}
);
};但是,所发布的数据并不带有预定义的参数,而是作为content_type : Application/JSON格式的原始体。
如何配置我的hl7_message post使用者以获取发布值的主体?例如req.body
发布于 2018-03-17 17:24:13
https://loopback.io/doc/en/lb3/Remote-methods.html#argument-descriptions
例如,将整个请求体作为值的参数: { arg:'data',键入:'object',http:{ source:'body‘}
您将在远程方法描述中将上述行添加到accepts数组中,并向函数本身添加额外的参数(data)。
Message.hl7_message = function (data, cb) {
console.log('my request body: ' + JSON.stringify(data));
cb(null, 'Success... ');
}
Message.remoteMethod(
'hl7_message', {
http: {
path: '/hl7_message',
verb: 'post',
status: 200,
errorStatus: 400
},
accepts: [{ arg: 'data', type: 'object', http: { source: 'body' } },
returns: {
arg: 'status',
type: 'string'
}
}
);https://stackoverflow.com/questions/49332510
复制相似问题