0

Under what circumstances a Restful call made with curl would be much faster than Spring's RestTemplate

I have to use Spring's RestTemplate's exchange methods as I am sending a JWT token as an Http Header (amongst others). The URL sits behind a DNS load balancer.

So curl command simply looks like curl -X POST "url" -H 'accept: /' -H Content-Type: application/json' -H 'Bearer: ' -d "body"

I am noticing 10 times the difference in Spring's RestTemplate (slower) as against curl call. So if curl returns the response in 1 second, the same is achieved by RestTemplate in no less than 11 or 12 seconds.

user721025
  • 172
  • 5
  • 15
  • I know this isn't really an "answer" but you should try using OkHttp instead of RestTemplate. It's a much better library imo and it might solve your issues without doing much. – aeskreis Aug 16 '23 at 21:16
  • You are comparing apples and oranges. The `RestTemplate` does a lot more then curl marshalling/unmarshalling to name one. It also depends on which HTTP library you are using, the default JDK one can be slow, you can try the Apache HTTP client for instance. – M. Deinum Aug 17 '23 at 07:29

0 Answers0