XML-RPC Beginner Guide
XML-RPC Beginner Guide
A typical request is when you open a website URL: in this moment the browser is actually sending an
HTTP request to the server, which contains, among other information, the URL you want.
RESPONSE - This is what the server respond to a request.
Again, when you ask the server for an URL, the response contains the HTML of that page (and other
hidden information).
(200 is the important part). If something goes wrong, the message change depending on the error (the well
known 404 Error for a not found page is the actual code provided in the header. 500 Error is a typical server
error message). The body is usually what we want to get from the server. Typically, is the HTML which is
rendered by the browser.
XML-RPC
XML-RPC is a remote procedure call (RPC) protocol which uses XML to encode its calls and HTTP as a
transport mechanism. [XML-RPC, Wikipedia]
Now let's forget about the form, and keep the everything else said so far.
Languages such as PHP and JavaScript can send HTTP requests without the need of an HTML form or any
HTML, as a matter of fact. And of course, they can read the response of that call.
If instead of sending a query string, we send an XML string, and the server accept this kind of requests, we can
use this system to send complex requests and, if needed return equally complex information.
I take for granted that you know what an XML file is.
Considering that an XML can basically contain any kind of information, you can do that:
XML-RPC method: wp.getComments Request:
<?xml version="1.0"?>
<methodCall>
<methodName>wp.getComments</methodName>
<params>
<param>
<value>
<string>1</string>
</value>
</param>
<param>
<value>
<string>xmlrpc-example</string>
</value>
</param>
<param>
<value>
<string>example-password</string>
</value>
</param>
<param>
<value>
<struct>
<member>
<name>post_id</name>
<value>
<int>41</int>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>
Response:
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value>
<struct>
<member>
<name>date_created_gmt</name>
<value>
<dateTime.iso8601>20081121T02:54:08</dateTime.iso8601>
</value>
</member>
<member>
<name>user_id</name>
<value>
<string>1</string>
</value>
</member>
----8<----snip----8<----snip----8<----snip----8<----snip----8<----snip
<member>
<name>type</name>
<value>
<string/>
</value>
</member>
</struct>
</value>
<value>
<struct>
<member>
<name>date_created_gmt</name>
<value>
<dateTime.iso8601>20081120T23:49:42</dateTime.iso8601>
</value>
</member>
<member>
<name>user_id</name>
<value>
<string>1</string>
</value>
</member>
<member>
<name>comment_id</name>
<value>
<string>7</string>
</value>
</member>
----8<----snip----8<----snip----8<----snip----8<----snip----8<----snip
<member>
<name>author_ip</name>
<value>
<string>::1</string>
</value>
</member>
<member>
<name>type</name>
<value>
<string/>
</value>
</member>
</struct>
</value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>
Of course, is possible to run actions which actually change the content in WordPress. For instance, you can
create a post, mark a comment as spam, etc.
WordPress provides APIs here: http://codex.wordpress.org/XML-RPC_WordPress_API
It's possible to modify WordPress XML-RPC methods, as well as creating brand new methods.
For instance, WPML does that, by extending the wp.newPost method with the language code. WPML also
adds new method and fields to translate a post, get translation informations about a post, etc.:
http://wpml.org/documentation/support/xml-rpc-language-interface/.