Created
June 25, 2018 17:13
-
-
Save asantos2000/35776780e0dd902cc33334b9d6dc4163 to your computer and use it in GitHub Desktop.
Dredd hook sample - Adding apikey to each request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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