Query Google from Java with nothing but the standard library, using serp.cheap — or drop in the official Java SDK (Spring Boot integration included). Either way it’s a plain HTTP+JSON endpoint.
Quick sanity check with curl first:
curl -X POST https://api.serp.cheap/v1/search \
-H "X-API-Key: $SERP_CHEAP_API_KEY" \
-H "Content-Type: application/json" \
-d '{"q":"best electric cars 2026","gl":"us"}'
The complete example
One file, runnable on Java 17+ with java.net.http for the request and Jackson for JSON (com.fasterxml.jackson.core:jackson-databind). Set SERP_CHEAP_API_KEY first.
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.List;
public class SerpSearch {
static final ObjectMapper M = new ObjectMapper();
@JsonIgnoreProperties(ignoreUnknown = true)
record Organic(int position, String title, String link, String snippet) {}
@JsonIgnoreProperties(ignoreUnknown = true)
record SearchResponse(List<Organic> organic) {}
public static void main(String[] args) throws Exception {
String key = System.getenv("SERP_CHEAP_API_KEY");
String body = M.writeValueAsString(new java.util.HashMap<>() {{
put("q", "best electric cars 2026");
put("gl", "us");
}});
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create("https://api.serp.cheap/v1/search"))
.header("X-API-Key", key)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> res = HttpClient.newHttpClient()
.send(req, HttpResponse.BodyHandlers.ofString());
SearchResponse data = M.readValue(res.body(), SearchResponse.class);
for (Organic r : data.organic()) {
System.out.printf("%2d. %s%n %s%n", r.position(), r.title(), r.link());
}
}
}
records map the JSON cleanly, and @JsonIgnoreProperties(ignoreUnknown = true) means new response fields never break your build.
Spring Boot
In a Spring app, wrap the same call in a @Service using RestClient (Spring 6.1+):
@Service
public class SerpClient {
private final RestClient http = RestClient.builder()
.baseUrl("https://api.serp.cheap")
.defaultHeader("X-API-Key", System.getenv("SERP_CHEAP_API_KEY"))
.build();
public SearchResponse search(String q, String gl) {
return http.post().uri("/v1/search")
.body(java.util.Map.of("q", q, "gl", gl))
.retrieve()
.body(SearchResponse.class);
}
}
The official Java SDK ships this wiring — plus retries, pagination and typed parameters — as a Spring Boot starter, so you inject SerpClient and go.
Parameters worth knowing
gl— country of results (us,de,br, …). See local SEO by country.hl— interface language.page— 1-indexed; each page is a separate request. See pagination.tbs— time filter (qdr:d= past day). See the full parameter reference.
Next
Try serp.cheap
Copy the file above, add your key, and you have live Google results in Java. 100 free searches on signup — no card required; pay-as-you-go from $0.75/1k after that, and credits stay valid for 12 months.
- Get your free API key →
- Prefer paying by card? serp.cheap is also on RapidAPI (
$0.90/1k) and Apify ($1.50/1k).