Skip to content

Instantly share code, notes, and snippets.

@asantos2000
Created June 25, 2018 17:13
Show Gist options
  • Save asantos2000/35776780e0dd902cc33334b9d6dc4163 to your computer and use it in GitHub Desktop.
Save asantos2000/35776780e0dd902cc33334b9d6dc4163 to your computer and use it in GitHub Desktop.
Dredd hook sample - Adding apikey to each request
// Writing Dredd Hooks In Node.js
// Ref: http://dredd.org/en/latest/hooks-nodejs.html
var hooks = require('hooks');
hooks.beforeEach(function(transaction) {
hooks.log('before each');
// add query parameter to each transaction here
let paramToAdd = 'api-key=23456';
if (transaction.fullPath.indexOf('?') > -1)
transaction.fullPath += '&' + paramToAdd;
else
transaction.fullPath += '?' + paramToAdd;
hooks.log('before each fullpath: ' + transaction.fullPath);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment