HTTP Post with no body in Angular

William Hampshire picture William Hampshire · Nov 22, 2017 · Viewed 27.9k times · Source

I'm wondering how to send an HTTP post request without a body (specifically in Angular). Here's what I'm doing now, but I'm getting the error Expected 2-3 arguments, but got 1).

I realize the second argument is for the body, but I'm not sending that to the server (yes, I understand that a POST call changes the state of a system and have looked into THIS question).

postRequest(id) {
  this.http.post('/api?data=' + id).map(
    (response) => {
      return response;
    }
  )
}

Answer

William Hampshire picture William Hampshire · Nov 28, 2017

Looks like this is the appropriate answer:

postRequest(id) {
  this.http.post('/api?data=' + id, null).map(
    (response) => {
      return response;
    }
  )
}