educative.io

Why can't we send parameters in the request body of a GET in practice?

Hi there! loving your course.

I came across a question and the answer intrigued me but left me wondering why.

in the quote below, can you folks share why we can’t do this in practice? (“But in practice, we can’t send the parameters in the request body of a GET method”). Is it because of caching or something else?

"Can we send parameters in the request body of a GET request instead of the URL?
Theoretically, sending parameters in the body of a GET request is possible. But in practice, we can’t send the parameters in the request body of a GET method. Even if we do send them this way, the server should ignore them. Usually, the length of the URL is also limited. If the limit is exceeded, then we can use the POST method to pass parameters in the request body. However, GET has the advantage of being slightly faster than POST because there is no request body.
"


Course: https://www.educative.io/courses/grokking-the-api-design-interview
Lesson: https://www.educative.io/courses/grokking-the-api-design-interview/JQjM6Z9Dk1y

Hi @Amit_L_Wadhwani,

Thank you for the valuable feedback on our course :raised_hands:. Here is the answer to your query:

It is not a common practice in industry to send parameters in the request body of a GET method. By convention, expects GET requests to retrieve resources and not have any side effects on the server.
However, there might be specific edge cases where sending parameters in the request body of a GET method could be necessary. For instance, in certain security mechanisms, there may be constraints on sending parameters in the URLs, which could lead to the consideration of using the GET request body instead. However, it’s important to note that such usage would require modifications to the server specification to process the GET request body properly.
In most cases, adhering to the standard practice of including parameters in the URL’s query string ensures compatibility, simplicity, and aligns with the expected behavior of the GET method in HTTP.

I hope this explanation helps clarify the reasoning behind “Why can’t we send parameters in the request body of a GET in practice?”. If you have any further questions, please feel free to ask!

1 Like