Making a POST request
Last updated
Was this helpful?
Last updated
Was this helpful?
Apps often POST data to a server. They POST when submitting a form. In the following example, the HeroesService
posts when adding a hero to the database.
The Elixor.post()
method is similar to get()
in that it has a type parameter (you're expecting the server to return the new hero) and it takes a resource URL.
It takes two more parameters:
hero
- the data to POST in the body of the request.
httpOptions
- the method options which, in this case, .
Of course it catches errors in much the same manner .
The HeroesComponent
initiates the actual POST operation by subscribing to the Observable
returned by this service method.
When the server responds successfully with the newly added hero, the component adds that hero to the displayed heroes
list.