ApiServer
Deadly simple API ”Server., (*1)
It was designed for Javascript clients:, (*2)
- Speaks JSON out of the box
- API calls are buffered for 50ms waiting for other requests to join
- The less we talk to the server the better.
- The server is implemented from scratch keeping easy of use in mind:
- API handlers are PHP functions or methods which are discovered with annotations
- Everything is compiled for speed.
How to use it
The bootstrap code (index.php) should look like this:, (*3)
require __DIR__ . '/vendor/autoload.php';
$api = new crodas\ApiServer(
__DIR__ . '/src/services' // my apis
);
$api->main();
/** @API array_sum */
function do_array_sum($args, $server) {
return array('array_sum' => array_sum($args));
}
A client is included in client/dist (You can build the source with bower install; gulp dist)., (*4)
Server.setUrl("http://api.foobar.com");
Server.exec("array_sum", [1,2,3]).then(function(result) {
console.error(result);
});
Server.exec("array_sum", [2,3]).then(function(result) {
console.error(result);
});