3

I am trying to make a patch/and post call to the server but it never gets to the server. I have tried doing this with postman and it works there. so I'm pretty sure its something with my code.

Basically, my post and patch are the same so i will only show the patch.

protected patch(url: string, body: any): Observable<any> {
    let options = this.getRequestOptions(body);
    return this.http.patch(this.baseUrl+url,JSON.stringify(body),options);
}
private getRequestOptions(body:any):RequestOptions{
    let cpHeaders = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: cpHeaders });

    return options;
}

please note that this.baseUrl = "http://localhost/blah/api/ and url is being passed in as test;

I would appreciate any help here. thanks in advance

Update

   [HttpPut]
    public virtual IHttpActionResult Patch([FromBody]T entity)
    {
        return Ok(_repository.Patch(entity));
    }

    [HttpPatch]
    public virtual IHttpActionResult WebPatch([FromBody]T entity)
    {
        return this.Patch(entity);
    }

I have a proxy config as subjected in comments below.

 {
  "/api": {
    "target": "http://localhost/QuickQuoteApi",
    "secure": false,
    "pathRewrite": {
      "^/api": ""
    }
  }
}
kboul
  • 13,836
  • 5
  • 42
  • 53
JamTay317
  • 1,017
  • 3
  • 18
  • 37

1 Answers1

12

Late response, but useful for future developers.

I had the same issue, it worked in Postman but not in Angular.

Since the patch object is an observable, you must subscribe for it to invoke the patch call.

this.patch(url, payload).subscribe(); // Executes path object
Dler Hasan
  • 133
  • 1
  • 5