1
votes

I am using angular-cli with proxy to send my requests to backend. My backend runs locally on port 5000 and angular application runs of default port 4200. Everything is fine for GET requests, however all my POST requests made with HttpClient are being sent as GET requests.

Other methods, like PUT, PATCH and so on works as expected.

My proxy configuration:

{
  "/api/*": {
    "target": "http://localhost:5000",
    "secure": false
  }
}

If anyone could explain why that is happening and If I'm using proxy correctly, I would be grateful.

EDIT:

Request is being made with service method:

logout(): Observable<any> {
    return this.http.post('api/v1/user/logout', {});
  }
1
There isn't enough information in this for us to help you. Please, include the code you are using to run the post operation. - R. Richards
Sorry, updated my question with request code. Request is really basic since all I wanted to achieve with it is sending a correct method. So far it's not happening. - Jakub Barański
in angular for all post request we have to send body also. here you are not adding any body. may be its creating problem. just create a variable let body = {}; and pass it as return this.http.post('api/v1/user/logout', body); try with this @jakub - Amit kumar
Thanks for suggestion. Unfortunately adding body doesn't change anything. Payload is discarded and GET request is sent. - Jakub Barański
I don't think post data is any factor in this. Empty post request are actually quite common. What is a problem is that when using angular-cli proxy, instead of POSTs I send GETs, regardless if they carry data or not. - Jakub Barański

1 Answers

0
votes

Problem was really stupid apparently. All i had to do is add / at the end of url and request with correct method was sent...