Home > Software engineering >  View complete API response in Angular?
View complete API response in Angular?

Time:01-25

I'm teaching myself Angular as a hobby, so please forgive me if this is a dumb question.

I'm trying to call an external API and view the entire response so I can figure out how to parse it. I have a service with a class like this:

export class DataService {

private REST_API_SERVER = 'https://my-api.url';

constructor(private httpClient: HttpClient) { }
  
public sendGetRequest(): Observable<any> {
   return this.httpClient.get(this.REST_API_SERVER);
  }
}

Then I have a component that executes a function like this on init:


  sendGetRequest(): void {
   var result = this.DataService.sendGetRequest();
  }

I've tried using things like:

console.log('result: '   JSON.stringify(result));

What gets written to console is:

result: {"source":{"source":{"source":{}}}}

How can I view the whole response?

CodePudding user response:

in your component when you execute the function sendGetRequest(){}

try to use it like this

sendGetRequest(): void {
  this.DataService.sendGetRequest().subscribe(resp=>{
     console.log(resp)
  });
}
  •  Tags:  
  • Related