storinka/invoke
Composer 安装命令:
composer require storinka/invoke
包简介
Invoke Core library
README 文档
README
PHP library for building fast and modern web APIs.
Installation
The library is still work-in-progress.
composer require storinka/invoke:^2 storinka/invoke-http:^2
Basic example
- Create
index.php
use Invoke\Invoke; function add(float $a, float $b): float { return $a + $b; } Invoke::create([ "add" ])->serve();
- Run a server
php -S localhost:8000 index.php
- Make a request
curl 'localhost:8000/add?a=2&b=2' # { "result": 4 }
Complex example
- Create a type
use Invoke\Data; class UserResult extends Data { public int $id; public string $name; }
- Create a method to get list of users
use Invoke\Method; class GetUsers extends Method { protected function handle(int $page, int $perPage): array { $usersFromDB = getUsersFromDb($page, $perPage); return UserResult::many($usersFromDB); } }
- Setup Invoke
use Invoke\Invoke; Invoke::create([ "getUsers" => GetUsers::class ])->serve();
- Run a server and try to invoke:
curl 'localhost:8000/getUsers?page=1&perPage=10' # { "result": [ ... ] }
统计信息
- 总下载量: 1.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-06
