XML-RPC Client and Server

1.3.2 · abandoned · verified Sun Apr 19

The `xmlrpc` package provides a pure JavaScript implementation of an XML-RPC client and server for Node.js environments. Its core differentiator is the exclusive use of JavaScript libraries for XML parsing (via `sax-js`) and XML building (via `xmlbuilder`), thereby avoiding native C dependencies and their associated build requirements. This allows developers to set up XML-RPC communication without needing a C compiler or specific system libraries. The package supports both client and server roles, enabling applications to make and receive XML-RPC method calls. Key features include configurable ISO 8601 date/time formatting for both encoding and decoding, and optional support for HTTP cookies to maintain session state. The latest stable version is 1.3.2, released in June 2016. Due to its age, it exhibits an effectively abandoned release cadence, with no updates in nearly a decade.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to set up both an XML-RPC server and client, allowing them to communicate locally. It registers a server method 'anAction' and then uses the client to invoke it, showcasing basic call and response patterns.

const xmlrpc = require('xmlrpc');

// Creates an XML-RPC server to listen to XML-RPC method calls
const server = xmlrpc.createServer({ host: 'localhost', port: 9090 });

// Handle methods not found
server.on('NotFound', function(method, params) {
  console.log('Method ' + method + ' does not exist');
});

// Handle method calls by listening for events with the method call name
server.on('anAction', function (err, params, callback) {
  console.log('Method call params for \'anAction\': ' + params);

  // ...perform an action...

  // Send a method response with a value
  callback(null, 'aResult');
});
console.log('XML-RPC server listening on port 9090');

// Waits briefly to give the XML-RPC server time to start up and start
// listening
setTimeout(function () {
  // Creates an XML-RPC client. Passes the host information on where to
  // make the XML-RPC calls.
  const client = xmlrpc.createClient({ host: 'localhost', port: 9090, path: '/'});

  // Sends a method call to the XML-RPC server
  client.methodCall('anAction', ['aParam'], function (error, value) {
    // Results of the method response
    console.log('Method response for \'anAction\': ' + value);
  });

}, 1000);

view raw JSON →