I have to call a REST webservice and I am planning to use RestTemplate. I looked at examples on how to make a GET request and they are as shown below.
String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/bookings/{booking}", String.class,"42","21");
In my case the RESTful url is something like below. How do I use RestTemplate in this case?
http://example.com/hotels?state=NY&country=USA
So my question would be how do I send request parameters for GET requests?
For example, the method getForObject() will perform a GET and return an object. getForEntity() : executes a GET request and returns an object of ResponseEntity class that contains both the status code and the resource as an object. getForObject() : similar to getForEntity() , but returns the resource directly.
RestTemplate will still be used. But in some cases, the non-blocking approach uses much fewer system resources compared to the blocking one.
the placeholders work the same for either type of url, just do
String result = restTemplate.getForObject("http://example.com/hotels?state={state}&country={country}", String.class,"NY","USA");
or better yet, use a hashmap for real name matching-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With