1

Hoping this question proves constructive and doesn't get me flamed ("have you tried google?"). I am slowly crawling out of java greenhorn status and am currently faced with a decision I need to make regarding a project I need to build for work that involves testing a RESTful service. We have an internal java framework setup that uses HTTPClient. However I have read a couple recommendations stating that when you are dealing with RESTful services you are better off using a REST-specific tool like Jersey. One of the developers here recommends I use RestTemplate. I have begun reading the RestTemplate documentation as well as going over the code for our own HTTPClient implementation. Basically I can A: build off the existing HTTPClient work to shoehorn into my own project or B: create an entirely new project using RestTemplate. A might be faster, whereas B might be more appropriate/valuable in the long term. As I prefaced, while I have a good groundwork of java knowledge laid out (dealing with classes, methods, modifiers, package structure, inheritance and composition, etc), I'm just now starting to grasp finer points like this problem I just described (which tools to use). I would be thrilled to get some expert input on some of the drawbacks and advantages that exist for either choice.

Additional note: I have used soapui a lot in dealing with REST services. My resulting familiarity with REST concepts has me leaning towards RestTemplate (once I start writing code it seems more plug and play with what I've been doing in soapui), but if HTTPClient can give me the same functionality, even if it's more verbose, and a chunk of the work has been done for me, I would like to hear reasons to just go the HTTPClient route.

Benny
  • 242
  • 1
  • 5
  • 17
  • RestTemplate is a convenience wrapper over HttpClient. It just simplifies and abstracts some of the most common use cases and code. – Kevin Dec 04 '12 at 04:30
  • Unless I get any other input I will probably use rest template. – Benny Dec 05 '12 at 01:43
  • Did an about face and have just been sorting out pure HTTPClient. Right now I'm trying to figure out why eclipse is telling me that there is no such method as .releaseConnection() :( – Benny Dec 06 '12 at 00:53
  • I think the OP want to know things such as: does it block, support HTTP/2, support streaming, how to connect via HTTPS, etc. I think it is totally valid. Actually, Googles leads me here( – WesternGun Mar 14 '19 at 15:23

1 Answers1

0

Note this from Spring 5 doc:

NOTE: As of 5.0, the non-blocking, reactive org.springframework.web.reactive.client.WebClient offers a modern alternative to the RestTemplate with efficient support for both sync and async, as well as streaming scenarios. The RestTemplate will be deprecated in a future version and will not have major new features added going forward. See the WebClient section of the Spring Framework reference documentation for more details and example code.

Also, check this answer: RestTemplate vs Apache Http Client for production code in spring project

Which mentions several points worthy of looking into.

WesternGun
  • 11,303
  • 6
  • 88
  • 157