Before request schema
This is the function schema which defines all the middleware to be run before calling sdk.request method. This will be the schema which will be used to inject middleware into your code.
The before request middleware takes in 3 arguments:
javascriptjavascript
const includeApiKey = (request, sdk, bundle) => {
if (bundle.authData.api_key) {
request.headers = {
...request.headers,
"Content-Type": "application/json",
Authorization: `Bearer ${bundle.authData.api_key}`,
};
}
return request;
};
module.exports
{
befores:[includeApiKey];
}
const before = require("./src/before");
module.exports = {
beforeRequest:
[...before.befores],
};
In the above example we can see that on the app schema, beforeRequest property is an array of functions which includes a function that puts API key into the header of the request.
Please note that beforeRequest method is called before each sdk.request method is called.