Nest: [Discussion] HttpPromiseModule, promise support for http module

Created on 18 Jul 2019  路  3Comments  路  Source: nestjs/nest

Feature Request

Is your feature request related to a problem? Please describe.

I don't like using observables for http requests. I would like to see the "option" of using Promises. This issue sums up my feelings on the matter perfectly https://github.com/nestjs/nest/issues/471

Describe the solution you'd like

I've created a HttpPromiseModule in my project that mirrors the HttpModule but without the Observable wrapping. This module is a lot easier to work with and matches the coding style on the backend better. I have a PR I can submit if you want to see the code.

Teachability, Documentation, Adoption, Migration Strategy

You use it the exact same way as the HttpModule except you use the HttpPromiseModule

What is the motivation / use case for changing the behavior?

Observables for http feels wrong/overkill. Tired of adding .toPromise() on all my http requests.

needs triage type

Most helpful comment

As mentioned here, our recommended way is to use Observable https://github.com/nestjs/nest/issues/471

If you want to use Promises, call .toPromise.
If you don't want to call .toPromise, you can wrap HttpService in, let's say, HttpPromiseService and just override methods, call .super() and add .toPromise() so you don't have to do it over and over again. Bringing 2 different modules for the sake of 1 method call is an overkill

All 3 comments

You can just call .toPromise() on the observable, so I really don't see the issue here.

EDIT:
Didn't realize you mentioned this.

As mentioned here, our recommended way is to use Observable https://github.com/nestjs/nest/issues/471

If you want to use Promises, call .toPromise.
If you don't want to call .toPromise, you can wrap HttpService in, let's say, HttpPromiseService and just override methods, call .super() and add .toPromise() so you don't have to do it over and over again. Bringing 2 different modules for the sake of 1 method call is an overkill

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZenSoftware picture ZenSoftware  路  35Comments

BrunnerLivio picture BrunnerLivio  路  40Comments

artjomzab picture artjomzab  路  33Comments

szkumorowski picture szkumorowski  路  62Comments

weeco picture weeco  路  28Comments