kurniawan26
kurniawan26

Reputation: 823

How to add parameter to header request?

I have this header :

var header = {
        'accept': 'application/json',
        'x-application-id':applicationId,
        'hashing': this.hashGenerator(location),
        'content-type': 'application/json'
    }  

also I have some condition like this :

if(this.props.token != null){
        header.access-token=this.props.token
}

but it seems I can't do like this to add a parameter

header.access-token

any idea to solve this ? Thanks beforehands.

Upvotes: 1

Views: 5463

Answers (2)

Rohit RC
Rohit RC

Reputation: 469

instead of header.access-token=this.props.token

you can simply use json format as below

headers: {'Authorization': '[API key]'},

Upvotes: 0

user3896501
user3896501

Reputation: 3037

try: res.headers['access-token'] = this.props.token

and also, for custom headers you might need to add a "x-" prefix

see https://www.w3schools.com/js/js_object_properties.asp for more about object properties in JS

Upvotes: 2

Related Questions