LoopBack developers often need to propagate information (aka “context”) from the HTTP layer all the way down to data source connectors. We hear this regularly in the LoopBack discussion forums and GitHub issues.
Consider the following examples:
- When querying a database for a list of “todo” items, return only the items owned by the currently logged-in user.
- When making a REST or SOAP request to a backend service, include a transaction/correlation ID from the incoming HTTP request headers in the outgoing HTTP request headers, so that these two requests can be linked together by logging and tracing tools.
- When formatting an error message, translate it to the language understood by the user, as indicated by the HTTP request header “Accept-Language”.
These examples share a common pattern: the app needs to access information in the layer handling incoming HTTP requests, but it is not included in the arguments (parameters) of remote method APIs.