I have a remote method where I'm putting my application logic, as below:
module.exports = function(Entity) {
HcpEntity.retrieveProfile = function(body, cb) {
process.nextTick(function() {
//TODO: Application Logic
}
}
}
And the corresponding model JSON snippet is:
{
"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"
}
}
}
}
I need to be able to access the incoming HTTP headers in the area marked as //TODO: Application Logic
so as to validate them. Could someone please help.
For the remote method accepts
use -
accepts: [
{arg: 'req', type: 'object', http: {source: 'req'}}
],
The request headers must be available in req.headers
.
See: https://loopback.io/doc/en/lb3/Remote-methods.html#http-mapping-of-input-arguments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With