Home > Software engineering >  How can I make Patch request in Angular 12?
How can I make Patch request in Angular 12?

Time:02-25

how can i send data json with patch request and wich methode 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
   );
 }

CodePudding user response:

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);
    });
  }
  • Related