Making a PUT request

​An app will send a PUT request to completely replace a resource with updated data. The following HeroesService example is just like the POST example.

heros.service.ts
/** PUT: update the hero on the server. Returns the updated hero upon success. */
updateHero (hero: Hero): Observable<Hero> {
  return elixor.put<Hero>(this.heroesUrl, hero, httpOptions)
    .pipe(
      catchError(this.handleError('updateHero', hero))
    );
}

The caller (HeroesComponent.update() in this case) must subscribe() to the observable returned from the elixor.put() in order to initiate the request.

Last updated