The example provided in the official Angular HttpClient documentation demonstrates how to make a POST request to a backend server.
/** POST: add a new hero to the database */
addHero (hero: Hero): Observable<Hero> {
return this.http.post<Hero>(this.heroesUrl, hero, httpOptions)
.pipe(
catchError(this.handleError('addHero', hero))
);
}
I find it puzzling that the Observable is returning Hero data instead of just a success code for a POST request. While I grasp the concept of type assertion for GET requests, I'm struggling to comprehend its use in this scenario.