crodas / api-server
API Server with PHP and MongoDB
v0.1.2
2016-03-21 03:37 UTC
Requires
- crodas/function-discovery: >=0.6.1
- pimple/pimple: ~1.0
This package is auto-updated.
Last update: 2024-12-12 19:45:18 UTC
README
Deadly simple API µServer.
It was designed for Javascript clients:
- 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:
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
).
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); });