Skip to content

Commit b69d079

Browse files
authored
feat: bundle http-client consumer skill (#7)
* feat: bundle http-client consumer skill * docs: clarify Skills CLI removal leftovers
1 parent 907f48d commit b69d079

9 files changed

Lines changed: 429 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: added
3+
type: minor
4+
---
5+
6+
Bundle the fast-forward-http-client consumer skill with executable examples, optional installation guidance and Composer discovery metadata.

‎AGENTS.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# fast-forward-http-client maintenance
2+
3+
This repository owns `fast-forward/http-client`. Read Composer metadata, source and
4+
tests before changing public integration. Preserve unrelated work. Run
5+
`composer install`, `composer validate --strict` and `composer dev-tools`.
6+
Keep merge, release and deployment decisions with the maintainer. Ordinary
7+
source/resources share this root contract; consumer procedures live in SKILL.md.
8+
9+
## Bundled consumer skill
10+
11+
Read [the consumer skill](resources/skills/fast-forward-http-client/SKILL.md) when changing application integration
12+
examples, consumer guides or the skill. Keep its version contract, references
13+
and executable examples aligned with the supported public API. The canonical
14+
distributable source is `resources/skills`; it needs no installed copy or host
15+
alias. Repository maintenance continues to follow this AGENTS.md.

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,12 @@ This package is open-source software licensed under the
118118

119119
Contributions, issues, and pull requests are welcome at
120120
[php-fast-forward/http-client](https://github.com/php-fast-forward/http-client).
121+
122+
## Consumer agent skill
123+
124+
The package includes [fast-forward-http-client](resources/skills/fast-forward-http-client/SKILL.md) for application integration.
125+
It supports `fast-forward/http-client:^1.2`; inspect the installed version.
126+
See [skill installation and lifecycle](resources/skills/fast-forward-http-client/references/installation.md) for
127+
optional project synchronization with `llm/skills ^1.15`, guarded manual
128+
project/global copies and a pinned Skills CLI alternative. Shipping files does
129+
not install tooling or activate the skill in an agent session.

‎composer.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
},
2424
"require-dev": {
2525
"fast-forward/dev-tools": "dev-main",
26-
"llm/skills": "^1.15"
26+
"nyholm/psr7": "^1.8"
27+
},
28+
"suggest": {
29+
"llm/skills": "Optionally synchronize the bundled consumer skill in your project."
2730
},
2831
"minimum-stability": "stable",
2932
"autoload": {
@@ -56,6 +59,9 @@
5659
},
5760
"grumphp": {
5861
"config-default-path": "vendor/fast-forward/dev-tools/grumphp.yml"
62+
},
63+
"skills": {
64+
"source": "resources/skills"
5965
}
6066
},
6167
"scripts": {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2025 Felipe Sayão Lobato Abreu
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
name: fast-forward-http-client
3+
description: Provide Fast Forward's Symfony-backed PSR-18 client, supply its required PSR-17 factories, and test success and transport failures without a network.
4+
license: MIT; see LICENSE
5+
compatibility: Supports fast-forward/http-client ^1.2 and PHP ^8.3. Requires Composer and declared extensions; inspect the installed version. Earlier releases are outside this contract.
6+
metadata:
7+
author: Fast Forward
8+
api-baseline: fast-forward/http-client ^1.2
9+
---
10+
11+
# Wire a PSR-18 HTTP client
12+
13+
Use this skill for an application consuming `fast-forward/http-client:^1.2`.
14+
Read its instructions, manifest/lockfile and installed source before editing.
15+
Run `composer show fast-forward/http-client`. For versions outside this contract,
16+
inspect matching documentation; do not silently upgrade the application.
17+
18+
## First working integration
19+
20+
Requires PHP ^8.3, Composer's application autoloader and this package's runtime
21+
dependencies. The direct example also needs `nyholm/psr7:^1.8`.
22+
With authority to install the dependency:
23+
24+
```sh
25+
composer require 'fast-forward/http-client:^1.2' 'nyholm/psr7:^1.8'
26+
```
27+
28+
Create `app.php` in the application root alongside composer.json/vendor:
29+
30+
```php
31+
<?php
32+
33+
declare(strict_types=1);
34+
35+
require __DIR__ . '/vendor/autoload.php';
36+
37+
use FastForward\Config\ArrayConfig;
38+
use FastForward\Container\ContainerInterface;
39+
use FastForward\Container\ServiceProvider\ArrayServiceProvider;
40+
use FastForward\Http\Client\ServiceProvider\HttpClientServiceProvider;
41+
use Nyholm\Psr7\Factory\Psr17Factory;
42+
use Psr\Http\Client\ClientExceptionInterface;
43+
use Psr\Http\Client\ClientInterface;
44+
use Psr\Http\Message\ResponseFactoryInterface;
45+
use Psr\Http\Message\StreamFactoryInterface;
46+
use Symfony\Component\HttpClient\HttpClient;
47+
use Symfony\Component\HttpClient\MockHttpClient;
48+
use Symfony\Component\HttpClient\Response\MockResponse;
49+
use Symfony\Component\HttpClient\Exception\TransportException;
50+
use function FastForward\Container\container;
51+
52+
$config = new ArrayConfig([ContainerInterface::class => [HttpClientServiceProvider::class]]);
53+
$factory = new Psr17Factory();
54+
$makeContainer = static function (MockHttpClient $transport) use ($config, $factory): ContainerInterface {
55+
return container(
56+
new ArrayServiceProvider([
57+
HttpClient::class => static fn(): MockHttpClient => $transport,
58+
ResponseFactoryInterface::class => static fn(): Psr17Factory => $factory,
59+
StreamFactoryInterface::class => static fn(): Psr17Factory => $factory,
60+
]),
61+
$config,
62+
);
63+
};
64+
$services = $makeContainer(new MockHttpClient(new MockResponse('{"ready":true}', ['http_code' => 200])));
65+
$client = $services->get(ClientInterface::class);
66+
$response = $client->sendRequest($factory->createRequest('GET', 'https://example.invalid/health'));
67+
if ($response->getStatusCode() !== 200 || (string) $response->getBody() !== '{"ready":true}') {
68+
throw new RuntimeException('Client response differs.');
69+
}
70+
$failedClient = $makeContainer(new MockHttpClient(static function (): never {
71+
throw new TransportException('offline fixture');
72+
}))->get(ClientInterface::class);
73+
74+
echo "integration ready\n";
75+
```
76+
77+
Run `php app.php`. It throws on a wrong result; success prints
78+
`integration ready`. It uses no production data and starts no server.
79+
80+
## Wiring and failure boundaries
81+
82+
The primary product is `FastForward\Http\Client\ServiceProvider\HttpClientServiceProvider`. Place that class in ArrayConfig under `FastForward\Container\ContainerInterface::class`, pass the config to `FastForward\Container\container($config)`, and request `Psr\Http\Client\ClientInterface`. It uses Symfony HttpClient::create and Psr18Client. A provider-only application may pass the provider class directly.
83+
84+
This package requires PSR-17 interfaces but does not ship a concrete message implementation or factory provider. In the application install `fast-forward/http-factory:^1.2` and register `FastForward\Http\Message\Factory\ServiceProvider\HttpMessageFactoryServiceProvider::class` before the client provider. Alternatively supply ResponseFactoryInterface and StreamFactoryInterface through your own ArrayServiceProvider. The direct example needs `nyholm/psr7:^1.8` explicitly; MockHttpClient/MockResponse come from the required Symfony component, not a test-only package.
85+
86+
Put custom factories/transport in an earlier ArrayServiceProvider; first successfully resolving source wins. Provider services are cached. A missing PSR-17 factory can make get(ClientInterface::class) fail even if has() is true. The helper constructs the composed container; your application passes the resolved client to services that send requests.
87+
88+
Read and validate application configuration before constructing a custom Symfony transport; this provider has no invented timeout/environment config key. For custom timeout/base URI/auth choose HttpClient::create($options) in an explicit factory. PSR-18 HTTP 4xx/5xx responses are returned normally; catch ClientExceptionInterface for client/transport failures. Keep credentials in the application's secret mechanism and avoid real network calls in tests.
89+
90+
The helper tries aggregate sources in registration order. A PSR container or
91+
not-found exception from one source permits fallback to another source; other
92+
throwables propagate. Source priority is therefore the first successful resolution,
93+
not a guarantee that an earlier broken factory terminates lookup. Nested provider
94+
list errors during helper composition are caught; if services are absent, inspect
95+
the raw configuration and resolve the provider directly to diagnose the failure.
96+
97+
## Verify integration
98+
99+
Run the [complete example](examples/integration.php) against the application's
100+
autoloader in a disposable process. It checks success and negative cases:
101+
102+
```sh
103+
php /path/to/fast-forward-http-client/examples/integration.php ./vendor/autoload.php
104+
```
105+
106+
Expected final marker: `fast-forward-http-client: ok`. Keep application-specific regression
107+
tests in its existing PHPUnit suite, with each fixture class in its same-named
108+
file. File copying, host discovery and completed agent tasks are different checks.
109+
For optional copying/synchronization load
110+
[installation and lifecycle](references/installation.md).
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require $argv[1] ?? dirname(__DIR__, 4) . '/vendor/autoload.php';
6+
7+
use FastForward\Config\ArrayConfig;
8+
use FastForward\Container\ContainerInterface;
9+
use FastForward\Container\ServiceProvider\ArrayServiceProvider;
10+
use FastForward\Http\Client\ServiceProvider\HttpClientServiceProvider;
11+
use Nyholm\Psr7\Factory\Psr17Factory;
12+
use Psr\Http\Client\ClientExceptionInterface;
13+
use Psr\Http\Client\ClientInterface;
14+
use Psr\Http\Message\ResponseFactoryInterface;
15+
use Psr\Http\Message\StreamFactoryInterface;
16+
use Symfony\Component\HttpClient\HttpClient;
17+
use Symfony\Component\HttpClient\MockHttpClient;
18+
use Symfony\Component\HttpClient\Response\MockResponse;
19+
use Symfony\Component\HttpClient\Exception\TransportException;
20+
use function FastForward\Container\container;
21+
22+
$config = new ArrayConfig([ContainerInterface::class => [HttpClientServiceProvider::class]]);
23+
$factory = new Psr17Factory();
24+
$makeContainer = static function (MockHttpClient $transport) use ($config, $factory): ContainerInterface {
25+
return container(
26+
new ArrayServiceProvider([
27+
HttpClient::class => static fn(): MockHttpClient => $transport,
28+
ResponseFactoryInterface::class => static fn(): Psr17Factory => $factory,
29+
StreamFactoryInterface::class => static fn(): Psr17Factory => $factory,
30+
]),
31+
$config,
32+
);
33+
};
34+
$services = $makeContainer(new MockHttpClient(new MockResponse('{"ready":true}', ['http_code' => 200])));
35+
$client = $services->get(ClientInterface::class);
36+
$response = $client->sendRequest($factory->createRequest('GET', 'https://example.invalid/health'));
37+
if ($response->getStatusCode() !== 200 || (string) $response->getBody() !== '{"ready":true}') {
38+
throw new RuntimeException('Client response differs.');
39+
}
40+
$failedClient = $makeContainer(new MockHttpClient(static function (): never {
41+
throw new TransportException('offline fixture');
42+
}))->get(ClientInterface::class);
43+
try {
44+
$failedClient->sendRequest($factory->createRequest('GET', 'https://example.invalid/health'));
45+
throw new RuntimeException('Transport failure unexpectedly succeeded.');
46+
} catch (ClientExceptionInterface) {
47+
}
48+
49+
echo "fast-forward-http-client: ok\n";

0 commit comments

Comments
 (0)