storinka / invoke
Invoke Core library
v2.0.9
2022-08-02 23:16 UTC
Requires
- php: ^8.1
- ext-json: *
- ext-mbstring: *
- php-ds/php-ds: ^1.4
- psr/container: ^2.0 | ^1.0
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2026-05-25 00:39:23 UTC
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": [ ... ] }
