Add screenshot capture to Spring Boot REST controllers. Use RestTemplate or WebClient for async capture.
Spring Web dependency
@RestController
public class ScreenshotController {
@GetMapping("/screenshot")
public ResponseEntity<byte[]> capture(@RequestParam(defaultValue = "https://example.com") String url) {
RestTemplate rest = new RestTemplate();
String apiUrl = "https://snapapi.tech/v1/screenshot?url=" + URLEncoder.encode(url, StandardCharsets.UTF_8)
+ "&api_key=" + apiKey + "&format=png";
byte[] image = rest.getForObject(apiUrl, byte[].class);
return ResponseEntity.ok().contentType(MediaType.IMAGE_PNG).body(image);
}
}
SnapAPI renders pages in a real Chromium browser, so JavaScript-heavy Spring Boot apps render perfectly. You get: