Quick links: Content - sections - sub sections
EN FR
Jelix 1.9.0-dev

Section: XML-RPC

« JSON-RPC ^ Web services SOAP »
Switch to language: FR

Table of content

Jelix supports xml-rpc. this a protocol specified for data exchange in XML format.A client send a request containing XML content, an action to execute and parameters. Server executes action indicated with its parameters and send back an XML result.

RPC = remote procedure call

Entry point

An XML-RPC request cannot be treated as a classic request, thus you can't use "classic" request object. You have to create a specific entry point in www/ directory, xmlrpc.php. This entry point will instantiate a jXmlRpcRequest instead of a jClassicRequest.

Use the command app:create-entrypoint, by indicating the type xmlrpc:


php dev.php app:create-entrypoint --type=xmlrpc xmlrpc.php

It will create the entrypoint xmlrpc.php into your www/ directory, and will declare it into the urls.xml and framework.ini.php files.

You can then retrieve an url for a xmlrpc action like this:


  $url = jUrl::get("module~action@xmlrpc");

Controller

As XML-RPC is a specific request type, a controller filename must be suffixed by ".xmlrpc.php". A "default" controller file would be: "default.xmlrpc.php". (it can co-exists with a "default" classic controller such as "default.classic.php").

Controller content is similar to those of a classic controller. You just have to use a jResponseXmlRpc response (alias:"xmlrpc"):


class defaultCtrl extends jController {

  function index(){

    $resp = $this->getResponse('xmlrpc');

    // any data types : integer, string, array, objects...
    $data_php = ... ;

    $resp->response = $data_php;

    return $resp;

  }
}

Client request

To send a XML-RPC request, as specified in [[http://xmlrpc.scripting.com|xml-rpc spec]], you have to use a specific XML string:


<?xml version="1.0" ?>
<methodCall>
   <methodName>module:default:index</methodName>
  <params>
     <param><string>Allo ?</string></param>
  </params>
</methodCall>

The <methodName> element indicates which action to execute. In a Jelix application, it must be an action selector, here myModule:default:index.

Note: "~" cannot be used as separator between module name and action name. It must be replaced by ":" (tilde character is not permitted in XML-RPC method name). As a result, it is mandatory to indicate in the selector: a module, a controller and an action.

To retrieve received parameters in your controller, you will do:


  $parameters = $this->param('params');

Of course, $parameters will contain "php" data. The XML string is automatically decoded by jXmlRpcRequest.