0

How can I send JSON data with patch request and which method to connect to API?

private baseUrlRemoveNotifications: string =
   "api/v1.0/UploadDownload/removeNotifications";  
public removeNotificationForUser(onlineUserModel: OnlineUserModel) {
   let username = onlineUserModel.userName;
   const url = `${this.baseUrlRemoveNotifications}`;
   const options = {
     headers: new HttpHeaders({
       "Content-Type": "application/json",
     }),
   };
   return this.http.patch(
     `${this.baseUrlRemoveNotifications}`,
     username,
     options
   );
 }
Jason Aller
  • 3,541
  • 28
  • 38
  • 38

1 Answers1

1

You can try with this slice of code :

public removeNotificationForUser(onlineUserModel: OnlineUserModel) {
    let targetUsername = onlineUserModel.userName;
    const url =
      this.baseUrlRemoveNotifications +
      "/" +
      this.cookieService.get("username") +
      "/" +
      targetUsername;
    const body = {};
    const options = {
      headers: new HttpHeaders({
        "Content-Type": "application/json",
        "X-XSRF-TOKEN": this.cookieService.get("XSRF-TOKEN"),
      }),
    };
    this.http.patch<any>(url, body, options).subscribe((data) => {
      console.log("hi this is put request", data);
    });
  }
Aymen Ragguem
  • 156
  • 2
  • 15