savantd

GET(with auth headers) customer with RestTemplate

Jun 23rd, 2019
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1.           RestTemplate restTemplate = new RestTemplate();
  2.           String customerAPIUrl = "http://localhost:9080/api/customer";
  3.           HttpHeaders headers = new HttpHeaders();
  4.  
  5.           headers.set("Authorization", "Bearer " + accessToken); //accessToken can be the secret key you generate.
  6.           headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
  7.           String requestJson = "{\"email\":\"[email protected]\"}";
  8.           HttpEntity <String> entity = new HttpEntity <> (requestJson, headers);
  9.           ResponseEntity <String> response = restTemplate.exchange(customerAPIUrl, HttpMethod.GET, entity, String.class);
Advertisement
Add Comment
Please, Sign In to add comment