16

What's the best way to make a REST call?

Should I use Apache Http Client or Should I use Spring Rest Template.

On what basis I can decide which one I should go for?

I need to make a call to this url-

http://localhost:8080/service/Service/v1/get/USERID=10000/profile.ACCOUNT.SERVICE"

And after getting the response back, I just need to see whether that response contains any particular string or not.

AKIWEB
  • 19,008
  • 67
  • 180
  • 294
  • See the answer by @skaffman in this question - [spring-integration-or-apache-http-client](http://stackoverflow.com/questions/6850344/spring-integration-or-apache-http-client). – S21st Feb 14 '13 at 03:38

1 Answers1

26

Spring RestTemplate follows the pattern for all the *Template classes within the core Spring framework and the various sub-frameworks: JdbcTemplate, HibernateTemplate, WebServiceTemplate etc etc.

The idea of all of these Template classes is to reduce the boilerplate code (exception handling, repetitive stuff and concentrate on your business logic). I would definitely use it over the simple HttpClient.

To get the class you'll need the spring-web dependency.

abalogh
  • 8,239
  • 2
  • 34
  • 49
  • Thanks abalogh for the suggestion, I was also planning to use RestTemplate. I am working with Eclipse and with Java project. How can I add RestTemplate libraries in my project? When I am putting `RestTemplate rt = new RestTemplate()`. It is showing, it cannot be resolved to a type. – AKIWEB Feb 14 '13 at 20:24