I am trying to make a POST request using @nestjs/axios and return the response.
This is my code:
verifyResponse(captcha_response: String): Observable<AxiosResponse<any>> {
return this.httpService.post('<url of rest endpoint to verify captcha>', {
captcha_response
});
}
However, Visual Studio Code says Cannot find name 'AxiosResponse'. Where can I import this from? This type was used in the Nest.js docs as Observable<AxiosResponse<Cat[]>>. I decided to remove this and just use the type Observable<any>.
This works. However, if I use console.log() to view the response I get this:
Observable { _subscribe: [Function (anonymous)] }
Most answers I found on StackOverflow suggest to use some variation of this:
return this.httpService.post('<url of rest endpoint to verify captcha>', {
captcha_response
}).pipe(map(response => response.data));
...but console.log() gives me this:
Observable {
source: Observable { _subscribe: [Function (anonymous)] },
operator: [Function (anonymous)]
}
Some other answers on StackOverflow suggest to use .toPromise(), but apparently this is deprecated.
All in all, I'm new to Nest.js and I'm super confused. Since I can't find one, I would be really grateful for a complete and up-to-date example of how to make a simple POST request and return the response as JSON.