I'm wondering if I can make just a http post request without subscribing on callbacks, something like this
this._http.post('/list/items/update?itemId=' + itemId + "&done=" + done, null);
instead of this
this._http.post('/list/items/update?itemId=' + itemId + "&done=" + done, null)
.subscribe();
I do not think you can.
http.post (and get, put, delete, etc) returns a cold Observable, i.e. an Observable for which "its underlying producer is created and activated during subscription" (https://medium.com/@benlesh/hot-vs-cold-observables-f8094ed53339#.tofgfsou4).
This means the the function represented by the Observable is activated only with the subscribe method.
I had the same question but then I figured out that I actually don't care if someone subscribes to the observable. I just want the POST request sent in any case. This is what I came up with:
The request is sent as soon as
connect()
is called. However, there is still an observable that the caller ofpostItem
can subscribe to if required. SincepublishReplay()
is used instead of justpublish()
, subscribing is possible even after the POST request completed.I'm using conversion to Promise (requires rxjs):