I have an Api REST that requires the apikey in the headers to validate, I am doing the query with angle 4, but the apikey is not sent in the headers.
If I do the query with PostMan it works without problem. I'm stuck at this point, I appreciate your help friends.
I need to send the "apikey" in the headers of the request something like that.
This is the component code.
import { Component } from '@angular/core'
import { OnInit } from '@angular/core';
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'
import 'rxjs/add/operator/map'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
private apiURL = 'http://192.168.1.53/joinn-api/v1'
data: any = {}
constructor(private http: HttpClient){
this.getData()
this.getEvents()
}
getData(){
let headers = new HttpHeaders()
headers = headers.append('Content-Type', 'application/json; charset=utf-8')
return this.http.get(this.apiURL + '/event/?token=cf6fb41f1d21834d34c8a8c8b3827181', {headers: headers})
.map((res: Response) => res.json())
}
getEvents(){
this.getData().subscribe(data => {
console.log(data)
})
}
}