Sending Request body for GET method in AXIOS throws error

As per my understanding, http allows to have a request body for GET method.

While this is technically true (although it may be more accurate to say that it just doesn’t explicitly disallow it), it’s a very odd thing to do, and most systems do not expect GET requests to have bodies.

Consequently, plenty of libraries will not handle this.

The documentation for Axois says:

  // `data` is the data to be sent as the request body
  // Only applicable for request methods 'PUT', 'POST', and 'PATCH'

Under the hood, if you run Axios client side in a web browser, it will use XMLHttpRequest. If you look at the specification for that it says:

client . send([body = null])

Initiates the request. The body argument provides the request body, if any, and is ignored if the request method is GET or HEAD.

Leave a Comment