Clearly SuperAgent supports custom HTTP headers:
request
.post(\'/api/pet\')
.send({ name: \'Manny\', species: \'cat\' })
.set(\'X-API-Key\', \'foobar\'
This could be the late answer but I have used superagent-use
plugin to inject a custom HTTP header in all the requests. First of all, you need to install superagent-use
npm install superagent-use --save
then require like this
// using plugin to intercept calls
var request = require('superagent-use')(require('superagent'));
then add the function as middlerware/interceptor
// interceptor used by superagent to add custom header for each request
request.use((req) => {
req.header.custom_header = any_value;
return req;
});
and finally
request
.get(url)
.query({ view: 'jsonView' }) // query string