Add the following to your pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then add the following to your dependencies:
<dependency>
<groupId>com.github.samuellembke</groupId>
<artifactId>googlepagespeedapiwrapperjava</artifactId>
<version>1.3-RELEASE</version>
</dependency>
You need to create a GooglePagespeed Instance:
GooglePagespeed pagespeed = new GooglePagespeed.Builder().build();
You can specify the network timeout for the API request and a custom api server url
GooglePagespeed pagespeed = new GooglePagespeed.Builder()
.timeout(120, TimeUnit.SECONDS)
.api("https://api.example.com")
.build();
You now need to create a PagespeedRequest
PagespeedRequest request = new PagespeedRequest.Builder()
.key("API-KEY")
.url("https://example.page.to.test.com")
.build();
Now you can execute the request and retrieve a PagespeedResponse
PagespeedResponse response = pagespeed.execute(request);
Retrieve the JSON response as string and parse it to JSON using org.json, or the json library of your choice
JSONObject jsonObject = new JSONObject(response.getResponse());