Body of Http.DELETE request in Angular2

前端 未结 12 1985
旧巷少年郎
旧巷少年郎 2020-12-02 08:23

I\'m trying to talk to a somewhat RESTful API from an Angular 2 frontend.

To remove some item from a collection, I need to send some other data in addition to the re

12条回答
  •  暖寄归人
    2020-12-02 09:27

    Below is the relevant code example for Angular 2/4/5 projects:

    let headers = new Headers({
      'Content-Type': 'application/json'
    });
    
    let options = new RequestOptions({
      headers: headers,
      body: {
        id: 123
      }
    });
    
    return this.http.delete("http//delete.example.com/delete", options)
      .map((response: Response) => {
        return response.json()
      })
      .catch(err => {
        return err;
      });
    

    Notice that body is passed through RequestOptions

提交回复
热议问题