Created
August 19, 2014 17:10
-
-
Save markselby/57409d514ff4bccd9f30 to your computer and use it in GitHub Desktop.
JSON API proxy debugger
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
// Don't forget to npm install hoxy | |
var hoxy = require('hoxy'); | |
var proxy = new hoxy.Proxy().listen(8080); | |
proxy.intercept({ | |
phase: 'request', | |
}, function(req, resp) { | |
console.log('\n\n=============================================='); | |
console.log('Request: ' + req.fullUrl()); | |
Object.keys(req.headers).forEach(function(header) { | |
console.log(' ', header, ':', req.headers[header]); | |
}); | |
}); | |
proxy.intercept({ | |
phase: 'response', | |
mimeType: 'application/json', | |
as: 'json' | |
}, function(req, resp) { | |
console.log('\nResponse :', resp.statusCode); | |
Object.keys(resp.headers).forEach(function(header) { | |
console.log(' ', header, ':', resp.headers[header]); | |
}); | |
console.log(JSON.stringify(resp.json, null, 2)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment