I went about implementing the API in Java and I didn’t really like the example so I thought I’d leave my own here for others to possibly use instead. The existing example doesn’t integrate the access token so I’m not even sure how it would work reliably and it also uses the Apache library and I wanted to create something without importing that using standard Java libraries.
This example specifically uses the player match history endpoint and omits the optional parameters for simplicity, but should be easy to expand on for other endpoints.
EDIT: The forum mangled the formatting, so you can see it all pretty like here: An example Java usage of the Halo API. · GitHub
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HaloApi {
private static final String TOKEN = “access_token_here”;
private static final String PLAYER_MATCHES = “https://www.haloapi.com/stats/h5/players/%s/matches”;
public static String playerMatches(String gt) throws IOException {
return api(String.format(PLAYER_MATCHES, gt));
}
private static String api(String url) throws IOException {
URL apiUrl = new URL(url);
HttpURLConnection urlConn = (HttpURLConnection)apiUrl.openConnection();
urlConn.setRequestMethod(“GET”);
urlConn.setRequestProperty(“Ocp-Apim-Subscription-Key”, TOKEN);
StringBuilder output = new StringBuilder();
BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
output.append(inputLine);
}
in.close();
return output.toString();
}
public static void main(String args) {
try {
System.out.println(playerMatches(“your_gt_here”));
} catch (IOException e) {
e.printStackTrace();
}
}
}
This only returns in String format, just like the documented examples, but if you wanted some handy JSON functionality I really liked the library I found here: http://www.json.org/java/ You can simply pass the resulting String into an org.json.JSONObject object and then you’ll be able to access all the information within quite easily.