Submodule 23.3: Sending data to the server

Update feedback.service.ts

Update feedback.service.ts as follows:

addFeedbacks(fb: Feedback): Observable<Feedback[]> {
  return this.http.post<Feedback[]>(baseURL + 'feedback', fb);
}

HttpClient.post constructs an Observable with configured POST request and when the Observable instance is subscribed, POST request is executed on the server.

In HttpClient.post method we need to pass URL, request body and optional http options such as headers, response type etc.  

The addFeedbacks method is similar with what we have used in the getFeedbacks(). The difference is that here we use post instead of get. Using this we can store the fb form group in the JSON file as a new member of the feedback array.