我有一个远程方法,我将我的应用程序逻辑放在下面:
module.exports = function(Entity) {
HcpEntity.retrieveProfile = function(body, cb) {
process.nextTick(function() {
//TODO: Application Logic
}
}
}
相应的模型JSON片段是:
{
"name": "HcpEntity",
"base": "Model",
"properties": {},
"methods": {
"retrieveProfile": {
"isStatic" : true,
"accepts": [
{
"arg": "Request",
"type": "object",
"required": true,
"http": {
"source": "body"
}
}
],
"returns": {
"arg": "Response",
"type": "object"
},
"http": {
"verb": "post"
}
}
}
}
我需要能够访问标记为//TODO: Application Logic
的区域中的传入HTTP标头,以便验证它们。有人可以帮忙。
答案 0 :(得分:6)
对于远程方法accepts
,请使用 -
accepts: [
{arg: 'req', type: 'object', http: {source: 'req'}}
],
请求标头必须在req.headers
。
请参阅:https://loopback.io/doc/en/lb3/Remote-methods.html#http-mapping-of-input-arguments