0

I am trying to get the response data from a REST API URL in my Angular 14 application. But it's not working. How to write a proper POST query?

Details:

getDetails(): Observable<string[]> {
    const url = '.../mrkc/prd/api/details';
    const headers = new HttpHeaders()
      .set('Content-Type', 'application/json')
    const body = [{""}]; 
    return this.http.post(url, body, { headers });
    }

    this.globalService.getDetails().subscribe({
    next: data => {
        console.log(data);
    },
    error: error => {
        console.error(error);
    }
});

All Details:

getAllDetails(): Observable<string[]> {
    const url = '.../mrkc/prd/api/allDetails';
    const headers = new HttpHeaders()
      .set('Content-Type', 'application/json')
    const body = [{"labels":{"GroupName":"Power","GroupMembers":{Oil:green}}}];
    
    return this.http.post(url, body, { headers });
}


this.globalService.getAllDetails().subscribe({
    next: data => {
        console.log(data);
    },
    error: error => {
        console.error(error);
    }
});
EMahan K
  • 417
  • 1
  • 19
  • 1) Is the request URL correct? Your last code example uses `..../allDetails`, but the curl command uses `..../getFamilyDetails`. 2) How exactly is your code not working? Do you get an error message? Or wrong result? – Helen Jul 15 '22 at 08:38

0 Answers0