PHP library for building fast and modern web APIs.
The library is still work-in-progress.
composer require storinka/invoke:^2 storinka/invoke-http:^2
- 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 }
- 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": [ ... ] }