0

In below I called web service with String parameter named "samana"

String samana= "000ABC";

RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
HttpEntity<String> requestEntity = new HttpEntity<String>(null, headers);

Table res = restTemplate
        .exchange("http://localhost:8090/tharindu/findAllComputers?saman=").concat(samana), HttpMethod.GET, requestEntity, Table.class)
        .getBody();

How to pass LocalDate parameter in RestTemplate webservice

LocalDate samana = LocalDate.now();

RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
HttpEntity<String> requestEntity = new HttpEntity<String>(null, headers);

Table res = restTemplate
        .exchange("http://localhost:8090/tharindu/findAllComputers?saman=").concat(samana), HttpMethod.GET, requestEntity, Table.class)
        .getBody();
  • If I understood correctly you want to pass a parameter to another service `restTemplate.exchange("http://localhost:8090/tharindu/findAllComputers?saman="+samana+"&date="+LocalDate.now().toString())`. You need to make sure that on the client side you convert the date from the right format. – tzortzik Jan 26 '21 at 12:33
  • @tzortzik Can't I send date as LocalDate(with out converting to string) – Gayan Sanjaya Jan 26 '21 at 13:11
  • All parameters added to the URI will end up being a string. You can format the date however you like. There's no way of sending the LocalDate directly to the other service using HTTP, at least in an easy way. – tzortzik Jan 26 '21 at 13:28

0 Answers0