Trying the new RESTful api for Openfire 3.10.0 Beta

A trio of scripts used to perform RESTful operations on a Openfire 3.10.0 (Beta) server.

The latest Beta version of Openfire XMPP Server (3.10.0) features a new REST API Plugin. This allows developers and administrators to perform operations on the server using HTTP gets and puts. Following are three scripts using that API, in perl, python and php. All do the same thing: get the roster for a particular XMPP user from the Openfire server for their domain. Authentication is by secret for simplicity (the plugin also will accept Basic HTTP Authentication, which is preferable for security reasons).

This perl script uses Miles Crawford’s REST::Client module to do its work.


use strict;
use REST::Client;

my $secret = 'xxxxxxxxxxxxxxx';
my $url = "";

my $client = REST::Client->new();

$client->addHeader('Authorization', $secret); 

my $response = $client->GET($url);

print $client->responseCode(), "\n";
print $client->responseContent();


For the python variation on the same theme, I’ve used the urllib2 module. It’s no accident that this is the shortest of the three scripts. Makes me wonder what else I could do more efficiently in python.

import urllib2

secret = 'xxxxxxxxxxxxx'

url = ''
opener = urllib2.build_opener()
opener.addheaders = [('Authorization', secret)]
response =
print response

Although there are at least two REST client libraries for php (HTTPful and Guzzle), in the example below I’ve fallen back to a file_get_contents sample method I found on Decibel Developer (thus avoiding the horrors of curl). See the file_get_contents doc for background. This was the only explicitly streams oriented method I used.


$secret = 'xxxxxxxxxxxxxxx';
$url = "";

$headers  = array(
   'http' => array(
       'method' => "GET",
       'header' => "Authorization: " . $secret . "\r\n"

$context = stream_context_create($headers);
$response = file_get_contents($url, false, $context);

echo $response;

This entry was posted in Development, Systems Analysis on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).