how can I pass a value key from a GET url response to another GET url as a parameter in Angular component ?
The first url needs to be execute first after that only second url must get execute. Any example that can be done with or without service ?
how can I pass a value key from a GET url response to another GET url as a parameter in Angular component ?
The first url needs to be execute first after that only second url must get execute. Any example that can be done with or without service ?
this.apiService.firstAPI().subscribe(res => {
if(res.body){
var id = res.body.data[0].id;
this.apiService.SecondAPI(id).subscribe(res => {
}
}
}
this way your second API will be called only when first API response comes.
as for the api service function
SecondAPI(id) {
return this.httpService.get('api/getmyData?id='+id);
}
{ "id": 1} . Now how can I pass this this id to second API as a parameter ?The RxJS way to do this is to use switchMap
this.http.get('/url1')
.pipe(
switchMap((res)=>{
return this.http.get('/url2' + res.id);
})
)
.subscribe((res)=>{
// Do whatever
});