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
74 changes: 70 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,38 @@ jobs:
with:
path: server

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

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

- name: Setup PHP
Expand Down Expand Up @@ -79,16 +101,38 @@ jobs:
with:
path: server

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

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

- name: Setup PHP
Expand All @@ -110,7 +154,7 @@ jobs:
resources/boost/skills/skir-server-development/references/procedures-and-routing.md \
resources/boost/skills/skir-server-development/references/scaffolding.md \
resources/boost/skills/skir-server-development/references/structures-and-validation.md \
resources/boost/skills/skir-server-development/references/studio-codecs-and-testing.md
resources/boost/skills/skir-server-development/references/studio-protocol-and-testing.md
do
grep -Fxq "$asset" build/archive-files.txt
done
Expand All @@ -123,8 +167,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 config repositories.server '{"type":"path","url":"../server","options":{"symlink":false}}' --json
if [ "${{ matrix.scenario }}" = 'both' ]
then
Expand Down Expand Up @@ -154,7 +198,7 @@ jobs:
test -f .agents/skills/skir-server-development/references/procedures-and-routing.md
test -f .agents/skills/skir-server-development/references/scaffolding.md
test -f .agents/skills/skir-server-development/references/structures-and-validation.md
test -f .agents/skills/skir-server-development/references/studio-codecs-and-testing.md
test -f .agents/skills/skir-server-development/references/studio-protocol-and-testing.md
if [ "${{ matrix.scenario }}" = 'both' ]
then
grep -Fq 'php-skir/client' AGENTS.md
Expand Down Expand Up @@ -183,16 +227,38 @@ jobs:
with:
path: server

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

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

- name: Setup PHP
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SkirRPC offers many of the same benefits as gRPC—shared method definitions, ge
- Route procedures to attributed or invokable Laravel controllers with native dependency injection, middleware, authorization, and Form Requests. See [Routing](docs/routing.md).
- Keep generated providers and manual handlers available for non-controller layouts. See [Routing](docs/routing.md#generated-procedure-providers).
- Inspect an endpoint's procedures through its opt-in Studio. See [Studio](docs/routing.md#studio).
- Configure dense JSON, standard JSON, or base64 dense JSON package-wide or per endpoint. See [Codecs](docs/codecs.md).
- Speak the standard SkirRPC protocol, so clients generated for any Skir language can call your endpoints. See [Wire protocol](docs/protocol.md).

## Quick start

Expand All @@ -34,13 +34,13 @@ composer require php-skir/server std-out/simple-data-objects
npm install --save-dev skir skir-simple-data-objects-generator
```

The package defaults match the paths used below. To customize manifest locations, generator execution, controller layout, Form Request generation, Studio, or codecs, publish `config/skir-server.php`:
The package defaults match the paths used below. To customize manifest locations, generator execution, controller layout, Form Request generation, or Studio, publish `config/skir-server.php`:

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

See [Scaffolding configuration](docs/scaffolding.md#configure-manifests-and-destinations) for the current keys and defaults. Calling `studio()` or `studio(false)` on a route overrides the Studio default, while an explicit codec passed to `Route::skirRpc()` overrides the configured codec.
See [Scaffolding configuration](docs/scaffolding.md#configure-manifests-and-destinations) for the current keys and defaults. Calling `studio()` or `studio(false)` on a route overrides the Studio default.

Define a Skir method:

Expand Down
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
"php": "^8.4",
"laravel/framework": "^13.0",
"nikic/php-parser": "^5.8",
"php-skir/runtime": "^0.1@dev|^0.2@dev",
"php-skir/runtime": "^0.2@dev",
"symfony/process": "^7.4|^8.0"
},
"require-dev": {
"laravel/pint": "^1.29",
"orchestra/testbench": "^11.0",
"php-skir/client": "^0.1@dev|^0.2@dev",
"php-skir/client": "^0.2@dev",
"phpunit/phpunit": "^12.5"
},
"autoload": {
Expand All @@ -49,14 +49,20 @@
"type": "path",
"url": "../runtime",
"options": {
"symlink": false
"symlink": false,
"versions": {
"php-skir/runtime": "0.2.x-dev"
}
}
},
{
"type": "path",
"url": "../client",
"options": {
"symlink": false
"symlink": false,
"versions": {
"php-skir/client": "0.2.x-dev"
}
}
}
],
Expand Down
3 changes: 0 additions & 3 deletions config/skir-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

declare(strict_types=1);

use Skir\Server\Codecs\DenseJsonCodec;

return [
'studio_enabled' => env('SKIR_SERVER_STUDIO_ENABLED', false),
'studio_query_key' => env('SKIR_SERVER_STUDIO_QUERY_KEY', 'studio'),
'codec' => DenseJsonCodec::class,

'manifests' => [
base_path('app/Skir/skirout/skir-server-manifest.json'),
Expand Down
73 changes: 0 additions & 73 deletions docs/codecs.md

This file was deleted.

50 changes: 50 additions & 0 deletions docs/protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Wire protocol

Endpoints registered with `Route::skirRpc()` speak the standard SkirRPC protocol, so any Skir client can call them: the `php-skir/client` package, or clients generated for TypeScript, Python, Go and the other languages Skir supports.

## Requests

A call is a `POST` whose body is either a JSON object or a colon-separated string. A `GET` carries the same string in its query string.

### JSON object

```bash
curl -X POST -H 'Content-Type: application/json' \
-d '{"method": "Square", "request": 5.0}' \
https://example.test/api/skir
```

`method` is the method name or its number. `request` may be dense or readable JSON. The response is **readable** JSON, which makes this form handy for debugging with curl.

### Colon-separated

```text
Square:1001::5
Square:1001:readable:5
```

This is the form upstream Skir clients send: `name:number:format:request`. When the number is present it identifies the method and the name is informational; when it is empty, the method is looked up by name. The response is **dense** JSON unless the format is `readable`.

A `GET` request uses the same string as its query string, for example `/api/skir?Square:1001::5`.

## Responses

A successful call returns `200` with `Content-Type: application/json` and the encoded response value:

```json
25
```

Failures return a JSON error body with a Skir error code:

| Status | Code | When |
| --- | --- | --- |
| 422 | `skir_invalid_request` | The body is not a valid SkirRPC request, the method name is ambiguous, or the request value does not match the method's request type. |
| 404 | `skir_method_not_found` | No method with that name or number is registered on the endpoint. |
| 422 | `skir_validation_failed` | A Form Request rejected the decoded input. |
| 403 | `skir_authorization_failed` | A Form Request's `authorize()` returned `false`. |
| 500 | `skir_invalid_response` | The method returned a value that cannot be serialized as its response type. |

## Studio

A `GET` without a query string, or with the configured Studio query key (`?studio` by default), renders Studio when it is enabled. See [Studio](routing.md#studio).
12 changes: 1 addition & 11 deletions docs/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,7 @@ app(SkirServer::class)->addMethod(
);
```

The endpoint accepts SkirRPC envelopes. With the default dense JSON codec:

```json
{"method":"Square","request":5.0}
```

The response is the raw encoded Skir value:

```json
25
```
The endpoint accepts standard SkirRPC requests, for example the body `Square:1001::5`, and answers with the encoded response value, `25`. See [Wire protocol](protocol.md) for every request form.

GET requests are also supported. Pass the method and a JSON-encoded request value as query parameters:

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 @@ -9,7 +9,7 @@
`authorize()` and `rules()`; scaffolded Form Requests deny access and validate nothing by default.

Method middleware does not protect Studio. Put middleware on the outer Skir route when Studio or the
complete endpoint must be private. Keep the server codec aligned with clients.
complete endpoint must be private.

Use the `skir-server-development` skill for procedure routing, scaffolding, Studio, codec, or testing
Use the `skir-server-development` skill for procedure routing, scaffolding, Studio, protocol, or testing
work.
6 changes: 3 additions & 3 deletions resources/boost/skills/skir-server-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ boundaries.
- Choosing or implementing generated standard PHP objects, Spatie Laravel Data objects, or Simple
Data Objects—including input hydration and validation: read
[structures and validation](references/structures-and-validation.md).
- Studio exposure, codecs, failures, or test coverage: read
[Studio, codecs, and testing](references/studio-codecs-and-testing.md).
- Studio exposure, the wire protocol, failures, or test coverage: read
[Studio, protocol, and testing](references/studio-protocol-and-testing.md).
- Tasks crossing these areas: read every relevant reference before changing code.

## Workflow
Expand All @@ -30,4 +30,4 @@ boundaries.
3. Implement explicit validation and authorization before registration. Decide separately whether
method middleware or outer-route protection owns the boundary.
4. Test success plus applicable validation, authorization, malformed input, duplicate registration,
Studio, middleware, and codec failures.
Studio, middleware, and malformed-request failures.
Loading
Loading