Login   Register  
PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of AJ  >  RPC API Framework  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Sample landing page.
Class: RPC API Framework
Implement RPC servers for different formats
Author: By
Last change: corrected example paths, assumed was in /api/ instead of at DOCUMENT_ROOT
Date: 2011-02-06 16:36
Size: 2,365 bytes
 

Contents

Class file image Download
<?php

set_include_path
(get_include_path() . ":{$_SERVER['DOCUMENT_ROOT']}");
error_reporting(E_ALL);

include_once 
"lib/core/Query.class.php";
include_once 
"lib/RPCEngine.class.php";

////////////////////////////////////////////////////////////////////////

/*
Request:
    clear && wget --post-data '<?xml version="1.0"?><methodCall><methodName>example.hello_world</methodName><params><param><value><string>Bob Dole</string></value></param></params></methodCall>' -qO- "http://api.example.com/?format=xml"
Response:
    <?xml version="1.0"?>
    <methodResponse>
        <params>
            <param>
                <value>
                    <string>Hello Bob Dole, how are you today?</string>
                </value>
            </param>
        </params>
    </methodResponse>

Request:
    clear && wget --post-data '<?xml version="1.0"?><methodCall><methodName>example.hello_world</methodName><params><param><value><string>Bob Dole</string></value></param></params></methodCall>' -qO- "http://api.example.com/?format=json"
Response:
    {"result":"Hello Bob Dole, how are you today?","error":null,"id":null}
    
Request:
    clear && wget --post-data '{ "method": "example.hello_world", "params": ["Bob Dole"], "id": 1}' -qO- "http://api.example.com/?format=xml&input=json"
Response:
    <?xml version="1.0"?>
    <methodResponse>
        <params>
            <param>
                <value>
                    <string>Hello Bob Dole, how are you today?</string>
                </value>
            </param>
        </params>
    </methodResponse>
    
Request:
    clear && wget --post-data '{ "method": "example.hello_world", "params": ["Bob Dole"], "id": 1}' -qO- "http://api.example.com/?format=xml&input=json&format=json"
    clear && wget --post-data '{ "method": "help.list_all", "params": ["Bob Dole"], "id": 1}' -qO- "http://api.example.com/?format=xml&input=json&format=json"
Response:
    {"result":"Hello Bob Dole, how are you today?","error":null,"id":null}    
*/

$output Get::param('format','/^(json|xml)$/','xml');
$input Get::param('input','/^(json|xml)$/','xml');

$request Post::raw();

$RPCRequest RPCRequestFactory::create($request$output$input);

$RPCEngine RPCEngine::factory();
$RPCResult $RPCEngine->execute($RPCRequest);

$RPCResult->render();
?>