Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access custom request headers node express

I am building a web api with Express and have not found information on accessing incoming custom request headers.

I will be expecting, for instance, that an incoming post request have a provider_identifier header. When I receive the request, I need to access that header information to validate their subscription.

Can someone point me in the right direction/provide advice on this?

router.post('myendpoint/', function(req, res){
    var providerId = req.????;
});
like image 971
KickinMhl Avatar asked Dec 30 '15 14:12

KickinMhl


1 Answers

Answering my own question here... was kindof a DUH moment for me.

Using above example, simply reference the headers collection like so:

var providerId = req.headers.provider_identifier;

One note: Use an underscore rather than a dash. "provider-identifier" doesn't work, but "provider_identifier" does.

like image 132
KickinMhl Avatar answered Oct 21 '22 22:10

KickinMhl