The HTTP API is commonly used through another programming language or environment, such as PHP or Python. The benefit is that it can be used by any code that can issue and process HTTP GET or POST transactions.
Java Example
The following is a simple example in Java:
// Display lists public static
String showLists () {
// cmd = show_lists
// realm = sample
// pwd = trelMark9
// csv = 1 so we’ll get CSV output
String cmd = “api.whatcounts.net/bin/api_web?cmd=show_lists” + “&r=myrealm&pwd=mypass&csv=1”;
// perform an HTTP GET for the data
String results = httpGET (cmd);
// display our results
System.out.println (results); }
// Perform an HTTP get for URL public static
String httpGET (String command) {
String rc = "";
if (!command.toLowerCase ().startsWith ("http://"))
command = "http://" + command;
try
{
URL url = new URL (command);
URLConnection conn = url.openConnection ();
conn.setDoInput (true);
conn.setUseCaches (false);
InputStream is = conn.getInputStream ();
BufferedReader d = new BufferedReader(new InputStreamReader(is));
String line = "";
while ((line = d.readLine ()) != null)
rc += line + "\n";
d.close ();
is.close ();
}
catch (Exception e)
{
}
return rc; }
An alternate Command example using one of the four possible, non-default API Clients* for a realm:
String cmd = “api.whatcounts.net/bin/api_web?cmd=show_lists” + “&r=myrealm&pwd=mypassalt&api_client=myClient&client_auth=clientauth&csv=1”;