Replies: 2 comments 3 replies
-
@klutzer It is already possible, but in my eyes not the right approach.
The much better solution I use is to call the plugin api in a
module.exports = {
configureHooks: function (api) {
api.hooks.onRequest.addHook('getCoffee', function (request) {
request.headers = Object.assign({
'X-Coffee': 'coffee with milk, no sugar',
}, request.headers);
});
api.hooks.onResponse.addHook('getCoffee', function (response) {
response.body = 'coffee with milk, no sugar';
delete response.parsedBody;
delete response.prettyPrintBody;
});
}
} The documentation is relatively difficult to understand, I'm just realizing. If you have any questions, just let me know. The best way to develop such a plugin is with the CLI. NodeJS may cache the script and that makes creating and executing the script in VSCode difficult. |
Beta Was this translation helpful? Give feedback.
-
For variables, I would have created a separate hook module.exports = {
configureHooks: function (api) {
api.hooks.onRequest.addHook('getCoffee', function (request, context) {
utils.setVariableInContext(
{
foo: "bar",
},
context
);
});
}
} |
Beta Was this translation helpful? Give feedback.
-
Is it possible to have a single file containing event scripts (like pre or post-request ones) and make it available for all other .http files in different folders of the project? I'm trying to create a "common.http" file containing global variables and scripts but even importing it to every file, the global event scripts aren't executed for requests outside the file. Any clues about that?
Beta Was this translation helpful? Give feedback.
All reactions