0

I want to set "API Key" and "Accept" in HTTP header. I would also like to add auth-token, page-no, page-size in the body. Can anybody help me?

Below is the code snippet I tried so far :

const body = {
            auth_token: '',
            type: 'matrix',
            page_no: '1',
            page_size: '20',
            keyword: 'j',
        };
        const header = new HttpHeaders();
        header.append('X-API-KEY', '');
        header.append('Accept', 'application/json');
         return this.http.get('', { headers: header} **body**)
            .map
            (
                (reponse: Response) => {
                    const resp = reponse.json();
                    return resp;
                }
            );
    }
AmiNadimi
  • 5,129
  • 3
  • 39
  • 55
BASIT ALI
  • 1
  • 3

2 Answers2

1

Instance of HttpHeaders is immutable, you have to do: let headers = new HttpHeaders(); headers = headers.append('X-API-KEY', '');

jedruniu
  • 520
  • 4
  • 13
1

Another way is

const header=new HttpHeader({
   'X-API-KEY': '',
   'Accept': 'application/json'
})
Eliseo
  • 50,109
  • 4
  • 29
  • 67