I created a rest API for login using Spring Boot, but in client(Java) I am not able to see response body.
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:9091/student/" + response))
.GET()
.header("Content-Type", "application/json")
.build();
HttpResponse<String> response1 =
client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("res: " + response1.body());
My function from controller is:
@RequestMapping(value = RequestPath.GET_STUDENT_BY_ID, method = RequestMethod.GET)
public ResponseEntity getById(@PathVariable UUID id){
StudentEntity res = studentService.findById(id);
return ResponseEntity.status(HttpStatus.OK).body(res);
}
I tested my API using postman and I am able to see the response body in json format.
Is there another way to get the response body using Java Http client?