Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,21 @@ jobs:
with:
path: client

- name: Resolve runtime branch
id: runtime-ref
run: |
branch="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}"
if git ls-remote --exit-code --heads https://github.com/php-skir/runtime.git "$branch" > /dev/null; then
echo "ref=$branch" >> "$GITHUB_OUTPUT"
else
echo "ref=main" >> "$GITHUB_OUTPUT"
fi

- name: Checkout runtime
uses: actions/checkout@v7
with:
repository: php-skir/runtime
ref: ${{ steps.runtime-ref.outputs.ref }}
path: runtime

- name: Setup PHP
Expand Down Expand Up @@ -100,10 +111,21 @@ jobs:
with:
path: client

- name: Resolve runtime branch
id: runtime-ref
run: |
branch="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}"
if git ls-remote --exit-code --heads https://github.com/php-skir/runtime.git "$branch" > /dev/null; then
echo "ref=$branch" >> "$GITHUB_OUTPUT"
else
echo "ref=main" >> "$GITHUB_OUTPUT"
fi

- name: Checkout runtime
uses: actions/checkout@v7
with:
repository: php-skir/runtime
ref: ${{ steps.runtime-ref.outputs.ref }}
path: runtime

- name: Setup PHP
Expand Down Expand Up @@ -135,8 +157,8 @@ jobs:
run: |
composer config minimum-stability dev
composer config prefer-stable true
composer config repositories.runtime '{"type":"path","url":"../runtime","options":{"symlink":false}}' --json
composer config repositories.client '{"type":"path","url":"../client","options":{"symlink":false}}' --json
composer config repositories.runtime '{"type":"path","url":"../runtime","options":{"symlink":false,"versions":{"php-skir/runtime":"0.2.x-dev"}}}' --json
composer config repositories.client '{"type":"path","url":"../client","options":{"symlink":false,"versions":{"php-skir/client":"0.2.x-dev"}}}' --json
composer require "php-skir/client:*@dev" --no-interaction --no-progress
composer require laravel/boost:^2.4 --dev --no-interaction --no-progress
test ! -L vendor/php-skir/client
Expand Down Expand Up @@ -169,10 +191,21 @@ jobs:
with:
path: client

- name: Resolve runtime branch
id: runtime-ref
run: |
branch="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}"
if git ls-remote --exit-code --heads https://github.com/php-skir/runtime.git "$branch" > /dev/null; then
echo "ref=$branch" >> "$GITHUB_OUTPUT"
else
echo "ref=main" >> "$GITHUB_OUTPUT"
fi

- name: Checkout runtime
uses: actions/checkout@v7
with:
repository: php-skir/runtime
ref: ${{ steps.runtime-ref.outputs.ref }}
path: runtime

- name: Setup PHP
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Laravel package for calling SkirRPC services through generated typed clients and

- Generate typed RPC clients from Skir schemas with the [client generation guide](docs/generating-clients.md).
- Use standard PHP objects, [Laravel Data](docs/laravel-data.md), or [Simple Data Objects](docs/simple-data-objects.md).
- Configure Laravel container resolution and matching wire codecs with the [configuration and codecs guide](docs/configuration-and-codecs.md).
- Configure the server URL and endpoint with the [configuration guide](docs/configuration.md).
- [Handle failures and test without network requests](docs/error-handling-and-testing.md).

## Quick start
Expand Down Expand Up @@ -62,12 +62,11 @@ composer dump-autoload
php artisan vendor:publish --tag=skir-client-config
```

Configure the server endpoint and matching wire codec:
Configure the server endpoint:

```dotenv
SKIR_CLIENT_BASE_URL=https://api.example.test
SKIR_CLIENT_ENDPOINT=/api/skir
SKIR_CLIENT_CODEC=dense_json
```

Call the service through the generated typed client:
Expand All @@ -92,5 +91,5 @@ Standard PHP is the dependency-light baseline. Use [`skir-laravel-data-generator
- [Generating clients](docs/generating-clients.md)
- [Laravel Data](docs/laravel-data.md)
- [Simple Data Objects](docs/simple-data-objects.md)
- [Configuration and codecs](docs/configuration-and-codecs.md)
- [Configuration](docs/configuration.md)
- [Error handling and testing](docs/error-handling-and-testing.md)
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
"type": "path",
"url": "../runtime",
"options": {
"symlink": false
"symlink": false,
"versions": {
"php-skir/runtime": "0.2.x-dev"
}
}
}
],
Expand Down
1 change: 0 additions & 1 deletion config/skir-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
return [
'base_url' => env('SKIR_CLIENT_BASE_URL'),
'endpoint' => env('SKIR_CLIENT_ENDPOINT', '/'),
'codec' => env('SKIR_CLIENT_CODEC', 'dense_json'),

'generator' => [
'node' => env('SKIR_CLIENT_NODE', 'node'),
Expand Down
69 changes: 0 additions & 69 deletions docs/configuration-and-codecs.md

This file was deleted.

42 changes: 42 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Configuration

Publish the Laravel configuration file:

```bash
php artisan vendor:publish --tag=skir-client-config
```

Set the server base URL and RPC endpoint:

```dotenv
SKIR_CLIENT_BASE_URL=https://api.example.test
SKIR_CLIENT_ENDPOINT=/api/skir
```

`SKIR_CLIENT_BASE_URL` has no default and is required; it identifies the server origin or shared API prefix. `SKIR_CLIENT_ENDPOINT` defaults to `/`.

`SkirConnector` trims a trailing slash from the base URL, while each request resolves the configured relative endpoint. Do not repeat the endpoint path in both values: use `https://api.example.test` plus `/api/skir`, not `https://api.example.test/api/skir` plus `/api/skir`.

## Resolve or construct the client

In Laravel, the service provider builds the client from the published configuration:

```php
use Skir\Client\SkirClient;

$client = app(SkirClient::class);
```

You can also construct one directly:

```php
use Skir\Client\SkirClient;

$client = new SkirClient('https://api.example.test', '/api/skir');
```

## Wire format

The client speaks the standard SkirRPC protocol, the same one upstream Skir clients use. Each call is a `POST` whose body is `MethodName:methodNumber::denseJsonRequest`, and the server answers with the response in dense JSON. Any SkirRPC server works, whether it is `php-skir/server` or a service written in another language.

See [Generating clients](generating-clients.md) for the typed generation workflow and [Error handling and testing](error-handling-and-testing.md) for transport failure handling and mocks.
14 changes: 4 additions & 10 deletions docs/error-handling-and-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ A 2xx response that cannot be decoded also throws `SkirClientException`, but wit

The exception boundary is deliberately narrow:

- Only a codec-thrown `SkirRuntimeException` during response decoding is wrapped as an invalid-response `SkirClientException`.
- Only a `SkirRuntimeException` thrown while decoding the response is wrapped as an invalid-response `SkirClientException`.
- A `SkirRuntimeException` thrown while encoding the request propagates directly.
- DNS, connection, and TLS failures propagate as `Saloon\Exceptions\Request\FatalRequestException` and do not have a response.
- An unsupported configured codec throws `SkirClientException` with both `method` and `response` set to `null`.

The following handler is specifically for the `SkirClientException` paths. It does not catch direct request-encoding or Saloon fatal-request exceptions:

Expand Down Expand Up @@ -68,7 +67,6 @@ final class SkirRpcClientTest extends TestCase
{
config()->set('skir-client.base_url', 'https://api.example.test');
config()->set('skir-client.endpoint', '/api/skir');
config()->set('skir-client.codec', 'dense_json');

$transport = app(TransportSkirClient::class);
$mockClient = new MockClient([
Expand All @@ -87,10 +85,8 @@ final class SkirRpcClientTest extends TestCase
$mockClient->assertSent(function (Request $request): bool {
return $request instanceof SkirRpcRequest
&& $request->resolveEndpoint() === '/api/skir'
&& $request->body()->all() === [
'method' => 'GetUser',
'request' => [42],
];
&& $request->descriptor->name === 'GetUser'
&& $request->body()->all() === 'GetUser:'.$request->descriptor->number.'::[42]';
});
$mockClient->assertSentCount(1);
}
Expand All @@ -100,7 +96,6 @@ final class SkirRpcClientTest extends TestCase
{
config()->set('skir-client.base_url', 'https://api.example.test');
config()->set('skir-client.endpoint', '/api/skir');
config()->set('skir-client.codec', 'dense_json');

$transport = app(TransportSkirClient::class);
$mockClient = new MockClient([
Expand All @@ -125,7 +120,6 @@ final class SkirRpcClientTest extends TestCase
{
config()->set('skir-client.base_url', 'https://api.example.test');
config()->set('skir-client.endpoint', '/api/skir');
config()->set('skir-client.codec', 'dense_json');

$transport = app(TransportSkirClient::class);
$mockClient = new MockClient([
Expand All @@ -152,4 +146,4 @@ final class SkirRpcClientTest extends TestCase

`MockClient` matches the configured response to `SkirRpcRequest`, records the outgoing request, and lets `assertSent()` verify the request class, endpoint, method name, and encoded body. `assertSentCount(1)` also guards against duplicate calls. No network call is made.

See [Configuration and codecs](configuration-and-codecs.md) for transport setup and codec selection, and [Generating clients](generating-clients.md) for the schema and generated classes used above.
See [Configuration](configuration.md) for transport setup, and [Generating clients](generating-clients.md) for the schema and generated classes used above.
2 changes: 1 addition & 1 deletion docs/laravel-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ composer dump-autoload

## Call the typed client

Configure the transport endpoint and matching codec as described in [Configuration and codecs](configuration-and-codecs.md), then use the generated client:
Configure the transport endpoint as described in [Configuration](configuration.md), then use the generated client:

```php
use Skir\Admin\GetUserRequestData;
Expand Down
2 changes: 1 addition & 1 deletion docs/simple-data-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ composer dump-autoload

## Call the typed client

Configure the transport endpoint and matching codec as described in [Configuration and codecs](configuration-and-codecs.md), then use the generated client:
Configure the transport endpoint as described in [Configuration](configuration.md), then use the generated client:

```php
use Skir\Admin\GetUserRequestData;
Expand Down
4 changes: 2 additions & 2 deletions resources/boost/guidelines/core.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
generator-owned and may be replaced; do not edit files inside it.

Prefer the generated typed client for application code. Use `Skir\Client\SkirClient::invoke()` only
for debugging or custom transport integrations. Keep the base URL, endpoint, and codec aligned with
for debugging or custom transport integrations. Keep the base URL and endpoint aligned with
the server.

Use the `skir-client-development` skill whenever generating or configuring a client, diagnosing
transport failures, choosing a codec, or writing client tests. Client tests must use Saloon mocks
transport failures, or writing client tests. Client tests must use Saloon mocks
and must not contact a real server.
2 changes: 1 addition & 1 deletion resources/boost/skills/skir-client-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typed clients over direct transport calls.

- Generation, generator configuration, Composer autoloading, Laravel config, or environment setup:
read [generation and configuration](references/generation-and-configuration.md).
- Invocation, codecs, exceptions, debugging, recovery, or network-free tests: read
- Invocation, exceptions, debugging, recovery, or network-free tests: read
[invocation, errors, and testing](references/invocation-errors-and-testing.md).
- Tasks spanning both areas: read both references before changing code.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ Set:
```dotenv
SKIR_CLIENT_BASE_URL=https://api.example.test
SKIR_CLIENT_ENDPOINT=/api/skir
SKIR_CLIENT_CODEC=dense_json
```

`SKIR_CLIENT_BASE_URL` is required. `SKIR_CLIENT_ENDPOINT` defaults to `/`; do not duplicate the
endpoint path in the base URL. `SKIR_CLIENT_CODEC` defaults to `dense_json` and must match the server.
endpoint path in the base URL.

Do not substitute repository-local wrapper commands or machine-specific absolute paths in reusable
package guidance. Use the consuming application's documented runtime surface when executing these
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@ Application code should call the generated methods so requests and responses ret
types. Use low-level `SkirClient::invoke()` only for debugging or custom integrations; it returns the
decoded transport value rather than a generated response object.

The client and server must use the same codec:

- `dense_json`: descriptor-driven JSON; structs are positional arrays.
- `standard_json`: readable JSON objects with named struct fields.
- `base64_dense_json`: dense JSON inside a base64-encoded JSON string.

An unsupported configured codec throws `SkirClientException` while Laravel resolves the transport.
The client speaks the standard SkirRPC protocol: it POSTs `MethodName:methodNumber::denseJson` and
decodes a dense JSON response, so it works against any SkirRPC server.

## Distinguish failures

| Boundary | Result | Inspect or correct |
|---|---|---|
| HTTP response considered failed, normally 4xx/5xx | `SkirClientException` with method and response | Inspect status/body and the server error policy |
| Successful HTTP response cannot be decoded | `SkirClientException` with method, null response, previous `SkirRuntimeException` | Verify response shape and matching codec |
| Request encoding fails | `SkirRuntimeException` propagates directly | Verify generated request values and codec input |
| Successful HTTP response cannot be decoded | `SkirClientException` with method, null response, previous `SkirRuntimeException` | Verify the endpoint is a SkirRPC server and the schemas match |
| Request encoding fails | `SkirRuntimeException` propagates directly | Verify generated request values |
| DNS, connection, or TLS fails | Saloon `FatalRequestException` propagates with no response | Inspect URL, DNS, TLS, and connectivity |
| Codec is unsupported | `SkirClientException` with null method and response | Correct the configured codec |

Responses Saloon does not classify as failed, including redirects by default, continue to decoding.
Catching only `SkirClientException` does not catch encoding or network failures.
Expand All @@ -45,7 +39,7 @@ $user = $client->getUser(new GetUserRequest(userId: 42));
$mockClient->assertSent(fn (Request $request): bool =>
$request instanceof SkirRpcRequest
&& $request->resolveEndpoint() === '/api/skir'
&& $request->body()->all()['method'] === 'GetUser'
&& $request->descriptor->name === 'GetUser'
);
$mockClient->assertSentCount(1);
```
Expand Down
Loading
Loading