I'm trying to call the twitch API. To call this api we need to specify a user key. How can i hide the key in my code? I have no idea how to do.
Package Version
------------------------------------------------------
@angular-devkit/architect 0.800.2 (cli-only)
@angular-devkit/core 8.0.2 (cli-only)
@angular-devkit/schematics 8.0.2 (cli-only)
@schematics/angular 8.0.2 (cli-only)
@schematics/update 0.800.2 (cli-only)
rxjs 5.5.12
in my app.component.ts file
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaderResponse, HttpHeaders, HttpResponse, HttpErrorResponse } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'TwitchApp';
twitch_api_key:string = 'test';
twitch_api_Url:string = 'https://api.twitch.tv/helix/users?id=44322889';
limit:string = '10';
constructor(private http: HttpClient,){}
ngOnInit(){
this.request();
}
request(){
let header = new HttpHeaders({
'Client-ID': this.twitch_api_key
})
var options = {headers: header}
this.http.get(this.twitch_api_Url,options).subscribe(
res => {
console.log(res)
},
(err: HttpErrorResponse) => {
console.log(err.error);
console.log(err.name);
console.log(err.message);
console.log(err.status);
}
)
}
}
In the main.js in web browser
constructor(http) {
this.http = http;
this.title = 'TwitchApp';
this.twitch_api_key = 'test';
this.twitch_api_Url = 'https://api.twitch.tv/helix/users?id=44322889';
this.limit = '10';
}
Thanks