Mayur Arora
Mayur Arora

Reputation: 447

Passing Custom Request Headers in Loopback

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.

Upvotes: 9

Views: 2030

Answers (1)

iliyarYi
iliyarYi

Reputation: 41

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

Upvotes: 0

Related Questions