Yesterday, I had the task to call some rest endpoints for a backend application. The backend application was a spring boot application and so I used the spring RestTemplate to call the service endpoints. The endpoint was consists of several requests with type GET, POST, DELETE. Everything was running fine except one, when I tried to make a GET request that has request body.
This was a GET request, that used the body to transport data. GET requests should pass data in form of request parameters, query strings or header information. It does not make sense, to use the body for get requests. Springs RestTemplate did think the same and did not send the data along with in the request, because GET requests should have request parameters not body entities. I was not able to change the rest service backend, as I was just a consumer and needed to get this going. So I needed to modify RestTemplate behavior to support this.
In this post, I will show how to use RestTemplate to make a GET request that has a request body.