Call SkirRPC services from Laravel through generated, typed PHP clients. Requests go out over Saloon using the standard SkirRPC protocol, so the server can be php-skir/server or a Skir service written in any other language.
Requirements: PHP 8.3+, Laravel 12 or 13, and Node.js for the Skir compiler.
- Generate typed RPC clients from Skir schemas with the client generation guide.
- Use standard PHP objects, Laravel Data, or Simple Data Objects.
- Configure the server URL, endpoint, and authentication with the configuration guide.
- Handle failures and test without network requests.
Install the client and standard PHP generator:
composer require php-skir/client
npm install --save-dev skir skir-php-generatorCreate skir-src/admin/users.skir:
struct GetUserRequest {
user_id: int32;
}
struct User {
user_id: int32;
name: string;
}
method GetUser(GetUserRequest): User = 3180856469;
Configure the root skir.yml:
generators:
- mod: skir-php-generator
outDir: skir/skirout
config:
namespace: SkirSkir owns the output directory and may replace its contents during generation.
Generate the client, configure Composer autoloading, and publish the Laravel config:
npx skir gen # or: php artisan skir:generate-client
npx skir-php-generator configure-composer
composer dump-autoload
php artisan vendor:publish --tag=skir-client-configConfigure the server endpoint:
SKIR_CLIENT_BASE_URL=https://api.example.test
SKIR_CLIENT_ENDPOINT=/api/skirIf the server expects a credential, configure it in the same file. For example, to send a shared secret in a custom header:
SKIR_CLIENT_AUTH_TYPE=header
SKIR_CLIENT_AUTH_HEADER=X-Internal-Token
SKIR_CLIENT_AUTH_TOKEN=your-shared-secretEvery request then carries X-Internal-Token: your-shared-secret. Bearer, basic, and custom authentication are covered in the configuration guide.
Call the service through the generated typed client:
use Skir\Admin\GetUserRequest;
use Skir\Admin\SkirRpcClient;
use Skir\Client\SkirClient as TransportSkirClient;
$client = new SkirRpcClient(app(TransportSkirClient::class));
$user = $client->getUser(new GetUserRequest(userId: 42));
echo $user->name;Standard PHP is the dependency-light baseline. Use skir-laravel-data-generator for Laravel Data or skir-simple-data-objects-generator for Simple Data Objects.
