Recently, I encountered a similar issue to the one discussed in this post.
Since the original question was posted in 2017, I was curious if there have been any advancements or simpler methods developed since then.
One idea that came to mind was using an HttpInterceptor to streamline services and classes, like the example below:
@Injectable({
providedIn: 'root'
})
export class ExampleService {
constructor(private http: HttpClient) { }
getHouse(): Observable<House> {
return this.http.get<House>("MyRestPath");
}
}
And a class utilizing this service might look something like this:
someRandomMethod(): void {
this.exampleService.getHouse().subscribe(house => {
console.log(house.doSomething()) // Pay attention to the method being called here
console.log(house.address) // And also accessing a field
})
}
Is it feasible to implement this approach, or do we still need to resort to the methods outlined in the previous question/answers?