crodas / api-server
基于PHP和MongoDB的API服务器
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-09-12 19:10:26 UTC
README
简单的API μ服务器。
它专为JavaScript客户端设计
- 默认输出JSON
- API调用将缓冲50ms,等待其他请求加入
- 与服务器交流越少,越好。
- 服务器从头开始实现,考虑到易用性
- API处理程序是PHP函数或方法,通过注解发现
- 所有内容都经过编译以提高速度。
如何使用它
引导代码(index.php)应如下所示
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)); }
client
包含在 client/dist
中(您可以使用 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); });