Passing Custom Request Headers in Loopback

2k views Asked by At

How do I pass custom request headers (X-TRANSACTION-ID,X_USER_ID) in loopback for a POST API. We have the headers part in the data source file. But how do I make it dynamic ? I am using a remote method. Adding headers to the context object's request seems to make no difference. Only if the headers are added to the data source file , they seem to have an effect.

1

There are 1 answers

0
iliyarYi On

for the related model, within its .js file, you can use a beforeRemote hook to modify the request before executing the remote method.

the context object(ctx) have access to both request/response. E.g: you should be able to access the request body with ctx.req.body