الانتقال إلى المحتوى
FrontendAngular· 7 دقائق للقراءة

http.get() Sends Nothing Until You Subscribe (and Every Subscribe Sends Again)

An HttpClient Observable is a blueprint for a request. Each subscription runs it again; no subscription runs nothing.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • Angular 22
محتويات المقال

A profile page goes live, and two bug reports arrive the same week. The backend team asks why GET /api/me is called three times on every page view. And users say the Save button does nothing: no error, no message, and the Network panel shows no PUT at all. Both bugs come from the same assumption about what one line, this.http.get(), actually does.

The common misconception

The belief: calling http.get() sends the request, like fetch() does. The it returns is a handle to that response, so subscribing to it twice simply reads the same answer twice.

It's an intuition most developers bring from elsewhere. fetch() starts the request the moment you call it, and a Promise holds one result that every .then() shares. An Observable looks like a Promise that can emit more than once, so it's natural to assume the same model. And in the simplest case, one subscribe() right after the call, both models predict the same thing: one request, one response. The differences only show up when there are zero subscribers or more than one.

What actually happens

The Observable is a blueprint; subscribe() runs it

HttpClient returns what RxJS calls a . Building it does no network work at all. Angular's HTTP guide describes these Observables as blueprints for requests: the request is dispatched only when something subscribes, and each subscription is independent. The RxJS guide puts it another way: subscribing to an Observable is like calling a function. Two calls run the function twice; two subscriptions run the request twice.

Being a blueprint is also what makes the rest of RxJS useful here. You can pipe map(), catchError() or retry() onto the Observable before anything is sent, and they apply to every request it makes. It's why the guide's recommended service simply returns this.http.get<User>(...) from a method: the service describes the request, and the caller decides when, and how often, it runs.

That explains the Save button. Its handler called this.http.put(...) and threw away the Observable it got back, so no request was ever made, and no error appeared because nothing had failed. The HTTP guide has an explicit reminder for exactly this: subscribe to mutation Observables, or they won't fire.

TypeScript profile-form.ts
import { HttpClient } from '@angular/common/http';import { Component, inject, signal } from '@angular/core';@Component({ selector: 'app-profile-form', templateUrl: './profile-form.html' })export class ProfileForm {  private readonly http = inject(HttpClient);  readonly draft = signal({ name: '', email: '' });  readonly saved = signal(false);  save() {    // Without subscribe(), put() would only build the request    this.http      .put('/api/me', this.draft())      .subscribe(() => this.saved.set(true));  }}

Every subscriber gets its own request

The three GETs come from the template. Each async pipe is its own subscriber, so a template that reads user$ three times runs the blueprint three times. The same applies to anything else that subscribes: a toSignal() call, a second subscribe() in a service, and the retry() operator, which recovers from an error by subscribing again and therefore sending a fresh request. Nothing in that template looks expensive, because the cost hides behind a pipe, which is why duplicate requests usually show up in the backend's logs before anyone spots them in the code.

TypeScript profile.ts
import { AsyncPipe } from '@angular/common';import { HttpClient } from '@angular/common/http';import { Component, inject } from '@angular/core';@Component({  selector: 'app-profile',  imports: [AsyncPipe],  template: `    <h1>{{ (user$ | async)?.name }}</h1>    <img [src]="(user$ | async)?.avatarUrl" alt="" />    <p>{{ (user$ | async)?.email }}</p>  `,})export class Profile {  private readonly http = inject(HttpClient);  // A blueprint: each async pipe subscribes and sends its own GET  readonly user$ = this.http.get<User>('/api/me');}

toSignal() subscribes once, immediately, and stores the latest value in a signal that the template can read as often as it likes. Reading a signal doesn't subscribe to anything. The subscription is cleaned up when the component is destroyed.

Unsubscribing cancels; completing ends it

The blueprint model has a useful side. Unsubscribing from an HttpClient Observable while the request is in flight aborts the request, which is why an async pipe cancels a slow request when the user leaves the page, and why switchMap drops stale searches. And once the response arrives, the Observable usually completes, so a finished request doesn't keep a subscription alive.

If you prefer signals all the way, httpResource() turns this around on purpose. It's built on HttpClient but starts its request eagerly, sends a new one when a signal it reads changes, and cancels the one still pending. The guide recommends it for reading data, not for mutations like PUT.

MythReality
http.get() sends the requestIt returns a blueprint; subscribe() sends it
A second subscriber reuses the responseIt sends a second request
An unsubscribed put() still savesNothing is sent, and nothing reports an error
Unsubscribing just ignores the answerIt aborts the request in flight
retry() replays the last responseIt subscribes again, so it sends again

How to apply it in your project

  1. Count requests in the Network panelOpen each main page with the Network panel filtered to Fetch/XHR. Every duplicated request points to an Observable with more than one subscriber.
  2. Find unsubscribed mutationsSearch for .post(, .put(, .patch( and .delete( and check that each result is subscribed to, returned to a caller that subscribes, or passed to an operator that does.
  3. Subscribe once per valueConvert template reads to toSignal() or a single @if (... | async; as x), and give services one method per request instead of shared Observables that many callers subscribe to.
  4. Share on purposeWhen several parts of the app need the same response, share it explicitly with a signal or shareReplay(), and decide when the cached value must be refreshed.

Key takeaways

  • HttpClient methods return cold Observables: blueprints that send nothing until something subscribes.
  • Each subscription sends its own request, including each async pipe, toSignal() and every retry().
  • A mutation you don't subscribe to never reaches the server, and no error tells you so.
  • Subscribe once and read the result many times, with toSignal(), a single async pipe or an explicit share.

📚 المصادر

  1. Making HTTP requests — Angular
  2. Observable — RxJS
  3. RxJS interop with Angular signals — Angular
  4. Reactive data fetching with httpResource — Angular
  5. shareReplay — RxJS

التعليقات (0)