Angular/RxJS 6: How to prevent duplicate HTTP requests? : <p>Currently have a scenario where a method within a shared service is used by multiple components. This method makes an HTTP call to an endpoint that will always have the same response and returns an Observable. Is it possible to share the first response with all subscribers to prevent duplicate HTTP requests?</p>

<p>Below is a simplified version of the scenario described above: </p>

<pre class="lang-js prettyprint-override"><code>class SharedService {
  constructor(private http: HttpClient) {}

  getSomeData(): Observable&lt;any&gt; {
    return this.http.get&lt;any&gt;('some/endpoint');
  }
}

class Component1 {
  constructor(private sharedService: SharedService) {
    this.sharedService.getSomeData().subscribe(
      () =&gt; console.log('do something...')
    );
  }
}

class Component2 {
  constructor(private sharedService: SharedService) {
    this.sharedService.getSomeData().subscribe(
      () =&gt; console.log('do something different...')
    );
  }
}
</code></pre>
