Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NestJs async httpService call

How can I use Async/Await on HttpService using NestJs? The below code doesn`t works:

async create(data) {
    return await this.httpService.post(url, data);
}
like image 729
Andre Baltieri Avatar asked Aug 18 '18 17:08

Andre Baltieri


1 Answers

As toPromise() is being deprecated, you can replace it with firstValueFrom or lastValueFrom

For example:

const resp = await firstValueFrom(this.http.post(`http://localhost:3000/myApi`)

https://rxjs.dev/deprecations/to-promise

like image 187
Guster Avatar answered Sep 28 '22 11:09

Guster