Search code examples
javaspring-bootpostresttemplate

Spring Boot RestTemplate post without response type


I need to call another api and I am trying to use postForEntity as below:

restTemplate.postForEntity(postUrl, request, responseType)

Now, the api that I am calling is returning an object of a particular type, let's say CustomerDto. But I am not interested in this object. I just want to post and I don't want anything in return so I don't want to create this CustomerDto class in my application. So, for this scenario, in the above statement, what should i replace for responseType. In case, I had wanted the returned object, I would have given CustomerDto.class in case of responseType, but I dont want anything in return, so what do I do?


Solution

  • You can use postForLocation instead of postForEntity.

    restTemplate.postForLocation(postUrl, request)