简体   繁体   中英

How can I make Patch request in Angular 12?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM