Wiki

Clone wiki

BukkitGames / The web API

What is the web API

The BukkitGames web API allows you to access information about the current HG match on your server by parsing the provided API. This means you can display up-to-date information about the HG match on your website.

How can I access it

First you need to enable the web API in the BukkitGames configuration file. When doing this remember to set a password for it as well. Restart your server. The API can now be access with the following URL:

<your server ip>:<web-api-port>/?password=<web-api-password>

Example usage of the API

Here is the source code of the "example.html" document provided together with the web API. You can access this document with

<your server ip>:<web-api-port>/example.html?password=<web-api-password>

#!html

<!doctype html>
<html>
<body>
<h1>Web-API example</h1>
<p>This is a rough example how the web API can be used to display information about the current game on your server.</p>

<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
var queryDict = {}
location.search.substr(1).split("&").forEach(function(item) {queryDict[item.split("=")[0]] = item.split("=")[1]});


$.getJSON( "/api.json?password" + (typeof queryDict['password'] !== 'undefined' ? '=' + queryDict['password'] : ''), function( data ) {
  var items = [];
  $.each( data, function( key, val ) {
    items.push( "<li id='" + key + "'>" + key + ": " + JSON.stringify(val) + "</li>" );
  });

  $( "<ul/>", {
    "class": "my-new-list",
    html: items.join( "" )
  }).appendTo( "body" );
}).fail(function(jqXHR, textStatus, errorThrown) { $("<div/>", { html: "Error while trying to load 'api.json': " + textStatus + '!<br />More information: ' + JSON.stringify(jqXHR).replace(/<(?:.|\n)*?>/gm, '') }).appendTo("body") })
</script>
</body>
</html>

Updated