I am building an app using node.js and testing with mocha + chai. Is there a way I can add custom headers to my GET and POST chai requests?
For example, I want something like (semi-pseudocode):
chai.request(server) .get('/api/car/' + data.car_id) .headers({'some_custom_attribute':'some_value'}) .end(function(err, res) { //do something });
And likewise with post:
chai.request(server) .post('/api/car/') .headers({'some_custom_attribute':'some_value'}) .send({car_id: 'some_car_id'}) .end(function(err, res) { //do something });
Can someone help?
Thanks in advance!
In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.
Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add. In the Name box, type the custom HTTP header name.
Chai HTTP provides an interface for live integration testing via superagent. To do this, you must first construct a request to an application or url. Upon construction you are provided a chainable api that allows you to specify the http VERB request (get, post, etc) that you wish to invoke.
Use set
function to set http headers:
chai.request(server) .get('/api/car/' + data.car_id) .set('some_custom_attribute', 'some_value') .end(function(err, res) { //do something });
setting-up-requests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With