Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a screenshot API from Spring Boot by keeping the provider key in server-side configuration, accepting a tightly validated URL, and sending a server-to-server HTTP request. Spring Initializr supplies the web project; you then choose the provider’s Java SDK or its REST endpoint. The REST contract described by Screenshot API uses POST /api/v1/screenshot, an API key (preferably in an authorization header), and a JSON body containing the target URL, viewport, image format, and fullPage. Because providers differ in whether they return image bytes, a hosted URL, or a job object, confirm that response contract before wiring your controller to production behavior.

What you will build

The example below creates a small Spring Boot service with one endpoint:

  • POST /screenshots accepts a target URL and capture options.
  • The browser-facing caller never sees the screenshot provider’s API key.
  • Your server validates input, calls the provider, and translates the provider response into your application’s response.

This is application-level integration guidance, not a provider-prescribed Spring controller. Keep the provider host, API key, endpoint path, and response mapping in configuration so they can be changed without a source rewrite.

Prerequisites and project creation

Spring’s getting-started guide states Java 17 or later, Gradle 7.5 or later or Maven 3.5 or later, and recommends Spring Initializr for a new application. Its quickstart recommends an IDE and a JDK such as BellSoft Liberica 17 or 21. These are the guide’s requirements; check the requirements for the exact Spring Boot release you select.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
  1. Open Spring Initializr and choose a current Spring Boot release that supports your installed JDK.
  2. Choose Maven or Gradle, the Java language, and the Spring Web dependency.
  3. Generate the project, import it into your IDE, and run the generated application. With the Gradle wrapper on macOS or Linux, the quickstart command is ./gradlew bootRun.
  4. Confirm the selected Java version with java -version and confirm the build tool wrapper works before adding provider code.

SDK or direct REST: which route fits?

Decision point Java SDK Direct REST
Provider library Screenshot API’s listing says a Java SDK is available for Spring Boot, Jakarta EE, and Android. No provider library is required; use Spring’s HTTP client.
Dependency management Add and upgrade the provider artifact; the listing shows org.screenshot-api:screenshot-api:1.0.0, but coordinates and versions can change. Manage only Spring and your normal HTTP-client dependencies.
HTTP control Convenience depends on the SDK’s current method signatures and supported options. Explicit control over headers, timeouts, retries, serialization, and logging.
Capture options Use only options exposed by the SDK version you installed. Send documented fields such as URL, viewport, image format, and fullPage; add others only when the current API documentation confirms them.
Response handling Use the SDK’s documented response model. Inspect status, content type, and body; do not assume the result is bytes or a URL.

The SDK listing establishes that a Java library exists, but the available documentation excerpt does not establish its current Java method signatures. Do not paste an SDK call copied from an old blog post without checking the provider’s current SDK page and artifact repository.

Secure configuration for the API key

Screenshot API documents API-key authentication and recommends an authorization header. Put the key in an environment-backed property, not in a browser URL, JavaScript bundle, Git repository, or exception message.

# application.properties
screenshot.provider.base-url=https://provider.example
screenshot.provider.endpoint=/api/v1/screenshot
screenshot.provider.api-key=${SCREENSHOT_API_KEY}
screenshot.provider.connect-timeout=5s
screenshot.provider.read-timeout=90s

The host above is intentionally a configuration value: replace it with the provider host from the current API documentation. Set the environment variable before starting the application:

export SCREENSHOT_API_KEY='replace-with-your-key'
./gradlew bootRun

Request and response models

Define only the fields your public endpoint needs. Constrain viewport dimensions and formats so a caller cannot use your service as an unrestricted proxy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
package com.example.screenshots;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;

public record ScreenshotRequest(
    @NotBlank @Pattern(regexp = "https?://.+") String url,
    @Min(320) @Max(3840) Integer viewportWidth,
    @Min(240) @Max(2160) Integer viewportHeight,
    @Pattern(regexp = "png|jpeg|webp") String imageFormat,
    Boolean fullPage
) {}

For the response, start with a neutral envelope while you verify the provider contract:

public record ScreenshotResult(
    int providerStatus,
    String contentType,
    byte[] imageBytes,
    String providerBody
) {}

Once the provider confirms that a successful response is always an image or always a URL, replace this diagnostic envelope with a stable application DTO. The provider documentation excerpt includes a JavaScript example that logs screenshotUrl, but it does not establish that every Java request returns a URL.

Direct REST integration with Spring’s RestClient

Spring Framework’s synchronous RestClient is suitable for a simple controller. The following service constructs the documented JSON fields and preserves the provider’s status, content type, and body for explicit mapping.

package com.example.screenshots;

import java.time.Duration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;

@Service
public class ScreenshotProviderClient {
  private final RestClient client;
  private final String endpoint;
  private final String apiKey;

  public ScreenshotProviderClient(
      RestClient.Builder builder,
      @Value("${screenshot.provider.base-url}") String baseUrl,
      @Value("${screenshot.provider.endpoint:/api/v1/screenshot}") String endpoint,
      @Value("${screenshot.provider.api-key}") String apiKey) {
    this.client = builder.baseUrl(baseUrl).build();
    this.endpoint = endpoint;
    this.apiKey = apiKey;
  }

  public ResponseEntity capture(ScreenshotRequest request) {
    return client.post()
        .uri(endpoint)
        .header(HttpHeaders.AUTHORIZATION, "Bearer " + apiKey)
        .contentType(MediaType.APPLICATION_JSON)
        .body(request)
        .retrieve()
        .toEntity(byte[].class);
  }
}

This compiles when the project includes Spring Web and validation dependencies. It assumes a bearer-style authorization header because that is the documented recommendation; if the provider specifies a different header scheme, change that one line. It also assumes the provider can be represented as bytes. If the successful response is JSON containing a URL or job identifier, change toEntity(byte[].class) to a DTO and handle polling or downloading according to the provider’s contract.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Expose a narrow Spring controller

package com.example.screenshots;

import jakarta.validation.Valid;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/screenshots")
public class ScreenshotController {
  private final ScreenshotProviderClient provider;

  public ScreenshotController(ScreenshotProviderClient provider) {
    this.provider = provider;
  }

  @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<byte[]> capture(@Valid @RequestBody ScreenshotRequest request) {
    ResponseEntity<byte[]> result = provider.capture(request);
    MediaType type = result.getHeaders().getContentType();
    MediaType safeType = type == null ? MediaType.APPLICATION_OCTET_STREAM : type;
    return ResponseEntity.status(result.getStatusCode())
        .header(HttpHeaders.CONTENT_TYPE, safeType.toString())
        .body(result.getBody());
  }
}

For a production API, replace pass-through status handling with an allow-list of successful provider statuses and your own error JSON. Also add authentication and authorization to /screenshots; otherwise anyone who can reach your application may spend your provider quota.

Calling your Spring endpoint

curl -X POST http://localhost:8080/screenshots 
  -H 'Content-Type: application/json' 
  -d '{
    "url":"https://example.com",
    "viewportWidth":1440,
    "viewportHeight":900,
    "imageFormat":"png",
    "fullPage":true
  }' -o result.png

If the provider returns JSON rather than image bytes, save the response as JSON, read the documented URL or job identifier, and perform the provider’s documented follow-up request. Do not infer that behavior from a field name alone.

Validation, SSRF, and operational safeguards

  • Allow only https (and http only when you explicitly need it).
  • Reject localhost, loopback, link-local, private-network, and cloud metadata addresses after DNS resolution. Re-check redirects, because a public URL can redirect to an internal address.
  • Set connection and read timeouts. A screenshot can legitimately take longer than a normal JSON request, but an unbounded request can exhaust servlet threads.
  • Limit body size and accepted option ranges. Cap full-page captures or require an authenticated role for them.
  • Redact authorization headers and target URLs if URLs can contain secrets. Never log the API key.
  • Use bounded retries only for transient network failures or documented 429/5xx responses. Do not blindly retry a request that may already have created a billable capture.
  • Measure provider status, latency, response size, and your own rejection reason. Keep provider and application errors distinguishable.

Common failures and fixes

401 or 403 from the provider

Check that the environment variable is present in the running process, that the header scheme matches the provider documentation, and that no reverse proxy strips Authorization. Rotate a key that may have appeared in logs.

404 on /api/v1/screenshot

Verify the provider host, API version, and whether the endpoint is relative to a versioned base URL. Keep the path in configuration so an API-version change does not require recompiling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

400 validation error

Compare JSON names and types exactly: URL, viewport dimensions, image format, and fullPage. Confirm allowed format spelling and whether dimensions belong in a nested viewport object in the current contract.

Successful status but unusable body

Inspect Content-Type and the raw body in a redacted development log. A JSON URL or asynchronous job requires a DTO and follow-up flow; image bytes require an image content type and size checks.

Timeouts or blank captures

Increase the read timeout only within a tested upper bound, and use provider-supported wait or rendering options when available. Check whether the target requires authentication, blocks automated browsers, or depends on a region-specific asset.

Leaked key or unexpected quota usage

Revoke and replace the key, remove it from source and client code, inspect access logs, and protect your Spring endpoint with authentication, rate limits, and per-user quotas.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and cost decisions

No latency, quota, price, or service-level figure is established by the documentation used here, so do not promise a response time or volume allowance. Benchmark your own target pages and plan against the provider’s current commercial documentation.

  • Reuse one HTTP client rather than creating a client per request.
  • Choose full-page mode only when needed; it generally increases rendering and response work.
  • Cache identical, non-sensitive captures when freshness permits, and include capture options in the cache key.
  • Use asynchronous jobs or a queue for user-independent batches, but make retries idempotent where the provider supports an idempotency key.
  • Stream large image responses where your chosen client supports it instead of buffering unbounded byte arrays.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. It removes cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. AI agents can use its MCP tools take_screenshot, get_page_info, and capture_pdf.

The one-call cURL request is:

curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://stripe.com 
  -o shot.webp

See the ScreenshotNeo documentation for all parameters and response details. Equivalent calls are:

# Python
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

// Node.js
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo has a free plan with 1,000 screenshots per month and no card; paid plans start at $5 for 3,000 screenshots. Every plan includes its features, including full-page and element capture, device and retina settings, PDF output, custom CSS and JavaScript, waits, request blocking, headers and cookies, geolocation, caching, signed links, webhooks, bulk capture, and a usage API. Create a free ScreenshotNeo account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

SDK path: when to choose it

Choose the Java SDK when its current release exposes the capture options and response type your application needs, and when you prefer provider-managed serialization over direct HTTP control. Before committing, verify the artifact version, Spring Boot compatibility, authentication configuration, timeout behavior, exception types, and whether the SDK supports viewport, format, and full-page fields. If any of those are unclear, the REST route is easier to audit because every header and JSON field is visible in your code.

Pre-production checklist

  • Java and Spring Boot versions match the selected release’s support matrix.
  • The key is injected server-side and absent from logs and client responses.
  • URL, redirect, DNS, viewport, and output-size limits are enforced.
  • The provider’s current success and error response schemas are mapped explicitly.
  • Timeouts, retry rules, rate limits, authentication, and monitoring are configured.
  • Tests cover a normal page, a redirect, a blocked page, an invalid URL, a provider 401, a timeout, and a malformed provider response.

Frequently Asked Questions

Can I call a screenshot API directly from a browser in a Spring application?

You can technically make a browser request, but exposing the provider key would let visitors reuse it. Proxy the request through authenticated server-side code instead.

Should screenshots be returned as bytes or as a URL?

Follow the provider’s documented contract. Model image bytes, a hosted URL, and an asynchronous job as different response types rather than guessing from an example field name.

Is the shown provider SDK dependency guaranteed to remain version 1.0.0?

No. The listed coordinate is a point-in-time example; verify the current artifact and compatibility before adding it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.