I am trying to integrate with LiChess Stream API documented here: https://lichess.org/api#operation/streamGame
As far as I can tell, when you make a GET call to above endpoint, the server keeps the connection open indefinitely and keeps sending JSON responses when the requested game updates. I tried invoking the API via Spring RestTemplate:
RestTemplate template = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
HttpEntity<String> entity = new HttpEntity<>("UsQjErWM", headers);
headers.setBearerAuth("<TOKEN>");
ResponseEntity<String> response = template.exchange("https://lichess.org/api/bot/game/stream/B4ClFYzJ", HttpMethod.GET, entity, String.class);
System.out.println(response);
But this hangs indefinitely. I am assuming that the RestTemplate is waiting for end of the response which wouldn't arrive. Is there a way to read the stream continuously(perhaps using some low-level Http classes from Java)?