Search code examples
node.jsnpmxml-rpc

Do you nou how to run xmlrpc requests from node.js?


I wonder what is the best way to use xmlrpc with node.js, there is a npm plugin but I can't find how to use it. Thank you!


Solution

  • A piece of code from a working project:

    const xmlrpc = require('xmlrpc');
    
    const client = xmlrpc.createSecureClient({
        host: 'yourhost'
        port: 'yourport'
        path: '/somepath'
    });
    
    function fetchData() {
        return new Promise((resolve, reject) => {
            const xmlData = {
                table: 'GroupAssign',
                limit: 1000,
                page : 0,
            };
    
            return client.methodCall('DataService.query', [
                xmlData.table,
                xmlData.limit,
                xmlData.page,
            ], (error, data) => {
                if (error) { return reject(error); }
                return resolve(data);
            });
        });
    }
    

    So you need to

    1. require xmlrpc
    2. create a client
    3. invoke methodCall with a method name as the first param