Skip to content

Instantly share code, notes, and snippets.

@theracingapi
Last active April 14, 2023 10:18
Show Gist options
  • Save theracingapi/85b20143df4cd488293e8c42ed9a6257 to your computer and use it in GitHub Desktop.
Save theracingapi/85b20143df4cd488293e8c42ed9a6257 to your computer and use it in GitHub Desktop.
Get today's advanced racecards, including UK & IRE odds, using Java (Standard Plan)
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpClient;
import java.net.URI;
import java.io.IOException;
import java.util.Base64;
class GetRacecards {
private static final String getBasicAuthenticationHeader(String username, String password) {
String valueToEncode = username + ":" + password;
return "Basic " + Base64.getEncoder().encodeToString(valueToEncode.getBytes());
}
public static void main(String[] args) {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.theracingapi.com/v1/racecards/standard"))
.header("Authorization", getBasicAuthenticationHeader("<USERNAME>", "<PASSWORD>"))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = null;
try {
response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(response.body());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment