[Solar-talk] Sungrazr_Server: Request for comments

Antti Holvikari anttih at gmail.com
Wed Dec 19 04:04:33 CST 2007


On Dec 19, 2007 1:53 AM, Clay Loveless <clay at killersoft.com> wrote:
>
> Example usage:
>
> server.php:
>
> $request = Solar::factory('Solar_Request');
> $server = Solar::factory('Sungrazr_Server', array('adapter' =>
> 'Sungrazr_Server_Adapter_JsonRpc'));
> $server->addClass('Vendor_Api_Stuff');
>
> $server->handle($request);
>
>
> So... the class:
>
> Vendor_Api_Stuff extends Sungrazr_Server_Handler:
> ...
> public function create($apikey, $properties) { ... }
>
>
> ... is callable like this:
>
> $url = 'http://example.com/api
>
> $call = array(
>      'method' => 'stuff.create',
>      'params' => array(
>          array('apikey' => 'foo'),
>          array('properties' => array(
>              'first_name' => 'John',
>              'last_name'  => 'Public',
>          )),
>      ),
>      'id' => 55
> );
>
>
> $call = json_encode($call);
>
> $req = new HttpRequest($url, HttpRequest::METH_POST);
> $req->setBody($call);
> $msg = $req->send();
>
>
> ... sends a message via POST to the JSON-RPC api that has a POST body
> of:
>
> {"method":"stuff.create","params":[{"apikey":"foo"},{"properties":
> {"first_name":"John","last_name":"Public"}}],"id":55}
>
>
> And receives a response of:
>
> {"result":{"success":true},"error":null,"id":55}
>
>
> ... more to come. But, that's what's there now. Comments/feedback
> welcome!

(Disclaimer: My experience with web services is close to zero, but... :-)

Why not create a new front/page controller pair instead of a '_Server' class?

Also, why not just prefix methods with something like "api" to inform
it's callable instead of @supports? "Coding" with docblocks seems
weird to me :-).

It looks really easy and simple to use, I hope I can try it out someday.

-- 
Antti Holvikari


More information about the Solar-talk mailing list