Imagine a unique service that performs various tasks such as:
interface Bar {
uuid: string;
}
public fetchDataFromApiEndpoint(): Observable<Bar> {
return this.http.get<Bar>('...')
}
Now, if you find yourself needing to append a unique identifier to the server response that you want to utilize in multiple locations, consider creating another service function like:
interface BarExtended extends Bar {
modifiedAt: number;
}
public fetchAndEnhanceDataFromApiEndpoint(): Observable<BarExtended> {
return this.fetchDataFromApiEndpoint().pipe(map(item => item.modifiedAt = Date.now()))
}
This approach allows you to enhance the data without subscribing directly to the Observable.