Search code examples
javascripthttpaxiosgetpostman

Why does Postman allow Body in GET requests?


I am using axios to interact with the backend server, and in the process, I found something interesting. In Postman, it is possible to attach data in the request Body and receive responses with the status 200. However, this seems not to be the case when implementing in the frontend. For example:

axios.get('[target_url]', {
    // would result in "ERROR_CODE_INTERNAL_SERVER_ERROR" (status `500`)
    'data': {
        'data1': 'value1',
        'data2': 'value2'
        // ...etc.
    }
}).then(response => console.log(response)); 

Many StackOverflow questions mention why GET requests do not allow request Body (update: see (1)). I would include some of them as references:

  1. HTTP GET with request body
  2. REST API HTTP GET with Body
  3. axios get request with body and header
  4. React JS - How to pass body request in GET of fetch

And it appears the suggested ways to do so, are to either, change it to a POST request, or transform data in request Body to params: Sending GET request parameters in body

(1): I might have misstated the meaning, and would like to re-define my statement to the below reference:

Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request.


Thus, I would genuinely like to take a step further and know the reasons why Postman allows request body for GET requests.

Thank you for your kind attention and all the help.


Solution

  • In RFC 2616

    4.3 Message Body

    ...A message-body MUST NOT be included in a request if the specification of the request method (section 5.1.1) does not allow sending an entity-body in requests...

    Neither Section 5.1.1 or Section 9.3 prohibits sending entity body for GET method so this was theoretically not a problem.

    Also in the latest one, RFC 9110 says

    ...content received in a GET request has no generally defined semantics...

    so this is still not technically prohibited.

    But this sentence has ambiguity, so some gateways would implement GET accepting request body while some would not. So for compatibility with most gateways, not sending request body for GET method is recommended.