Skip to content

Commit e0efbf2

Browse files
committed
Add documentation for HTTP service providers and usage examples
- Introduced `HttpClientServiceProvider` and `HttpMessageFactoryServiceProvider` documentation. - Updated API reference to include new service providers. - Enhanced `HttpServiceProvider` documentation with usage examples and purpose. - Added compatibility and dependencies documentation. - Expanded FAQ section to clarify package usage and standards. - Created detailed guides for getting services, handling server requests, and using the HTTP client. - Added use cases demonstrating practical applications of the package. - Included coverage and links documentation for better navigation and understanding. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent cb0d761 commit e0efbf2

27 files changed

Lines changed: 1447 additions & 102 deletions

README.md

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,80 @@
1-
# Fast Forward Framework
1+
# Fast Forward HTTP
22

33
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
4-
[![PHP Version](https://img.shields.io/badge/php-^8.2-blue.svg)](https://www.php.net/releases/)
4+
[![PHP Version](https://img.shields.io/badge/php-^8.3-blue.svg)](https://www.php.net/releases/)
55

6-
**Fast Forward** is a lightweight and fast PHP framework designed for building modern web applications.
7-
This package serves as an **aggregate metapackage**, bundling all http components of the Fast Forward ecosystem for easier installation and management.
6+
Fast Forward HTTP is the aggregate HTTP package of the Fast Forward ecosystem.
87

9-
---
8+
It is designed for developers who want a practical starting point for HTTP work without wiring each
9+
piece manually. Install one package, register one provider, and you get the default Fast Forward
10+
HTTP stack in your container.
1011

11-
## Features
12+
## What You Get
1213

13-
- 🚀 **Modern PHP 8.3+ syntax**
14-
- ⚙️ Aggregates key components:
15-
- [`fast-forward/http-message`](https://github.com/php-fast-forward/http-message) – PSR-7 compatible HTTP message implementation
16-
- [`fast-forward/http-factory`](https://github.com/php-fast-forward/http-factory) – HTTP factory for creating PSR-7 request and response objects
17-
- [`fast-forward/http-client`](https://github.com/php-fast-forward/http-client) – PSR-18 compatible HTTP client for making requests
18-
- 📦 Simplifies installation of all http packages in one step
19-
- 🧱 Provides a solid foundation for building scalable Http PHP applications
20-
21-
---
14+
- PSR-17 factories for requests, responses, server requests, streams, uploaded files, and URIs
15+
- A PSR-18 HTTP client backed by Symfony HttpClient
16+
- A `ServerRequestInterface` created from PHP globals
17+
- Fast Forward convenience factories for JSON, HTML, text, redirect, empty responses, and payload streams
18+
- One aggregate `HttpServiceProvider` that wires the stack together
2219

2320
## Installation
2421

25-
Install via [Composer](https://getcomposer.org):
26-
2722
```bash
2823
composer require fast-forward/http
2924
```
3025

31-
This command will automatically pull in all the required dependencies of the framework.
26+
## Quickstart
3227

33-
---
28+
```php
29+
<?php
3430

35-
## Requirements
31+
declare(strict_types=1);
3632

37-
- PHP 8.2 or higher
33+
use FastForward\Http\Message\Factory\ResponseFactoryInterface;
34+
use FastForward\Http\ServiceProvider\HttpServiceProvider;
35+
use function FastForward\Container\container;
3836

39-
---
37+
$container = container(new HttpServiceProvider());
4038

41-
## License
39+
$responseFactory = $container->get(ResponseFactoryInterface::class);
40+
41+
$response = $responseFactory->createResponseFromPayload([
42+
'message' => 'Hello, Fast Forward HTTP!',
43+
'ok' => true,
44+
]);
45+
46+
echo $response->getHeaderLine('Content-Type');
47+
// application/json; charset=utf-8
48+
```
4249

43-
Fast Forward Framework is licensed under the [MIT license](LICENSE).
50+
## Main Services
4451

45-
---
52+
| Identifier | Default concrete service | Purpose |
53+
| --- | --- | --- |
54+
| `Psr\Http\Message\RequestFactoryInterface` | `Nyholm\Psr7\Factory\Psr17Factory` | Create outbound requests |
55+
| `Psr\Http\Message\ResponseFactoryInterface` | `Nyholm\Psr7\Factory\Psr17Factory` | Create plain PSR-17 responses |
56+
| `FastForward\Http\Message\Factory\ResponseFactoryInterface` | `FastForward\Http\Message\Factory\ResponseFactory` | Create JSON, HTML, text, redirect, and empty responses |
57+
| `FastForward\Http\Message\Factory\StreamFactoryInterface` | `FastForward\Http\Message\Factory\StreamFactory` | Create payload-aware JSON streams |
58+
| `Psr\Http\Message\ServerRequestInterface` | `ServerRequestCreator::fromGlobals()` result | Access the current incoming request |
59+
| `Psr\Http\Client\ClientInterface` | `Symfony\Component\HttpClient\Psr18Client` | Send outbound HTTP requests |
4660

47-
## Author
61+
## Documentation
62+
63+
See the documentation sources in [`docs/`](docs/) for:
64+
65+
- installation and quickstart
66+
- retrieving services from the container
67+
- responses, streams, and server requests
68+
- advanced customization and aliasing
69+
- aggregated services and compatibility notes
70+
71+
## Related Packages
72+
73+
- [`fast-forward/container`](https://github.com/php-fast-forward/container)
74+
- [`fast-forward/http-client`](https://github.com/php-fast-forward/http-client)
75+
- [`fast-forward/http-factory`](https://github.com/php-fast-forward/http-factory)
76+
- [`fast-forward/http-message`](https://github.com/php-fast-forward/http-message)
77+
78+
## License
4879

49-
Developed with ❤️ by **Felipe Sayão Lobato Abreu**
50-
📧 [github@mentordosnerds.com](mailto:github@mentordosnerds.com)
80+
Fast Forward HTTP is licensed under the [MIT license](LICENSE).

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"ergebnis/composer-normalize": true,
4141
"fast-forward/dev-tools": true,
4242
"phpdocumentor/shim": true,
43-
"phpro/grumphp": true
43+
"phpro/grumphp": true,
44+
"pyrech/composer-changelogs": true
4445
},
4546
"platform": {
4647
"php": "8.3.0"

docs/advanced/aliases.rst

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,66 @@
11
Aliases
22
=======
33

4-
The package registers standard PSR interfaces as service aliases in the container, allowing you to type-hint against PSR-7, PSR-17, and PSR-18 interfaces and retrieve the correct implementation automatically.
4+
The default setup relies heavily on aliases so you can request standard PSR interfaces and still
5+
receive a concrete implementation automatically.
6+
7+
Alias Map
8+
---------
9+
10+
.. list-table::
11+
:header-rows: 1
12+
:widths: 38 32 30
13+
14+
* - Requested identifier
15+
- Resolves to
16+
- Why this alias exists
17+
* - ``Psr\Http\Message\RequestFactoryInterface``
18+
- ``Nyholm\Psr7\Factory\Psr17Factory``
19+
- One factory can create PSR-7 request objects
20+
* - ``Psr\Http\Message\ResponseFactoryInterface``
21+
- ``Nyholm\Psr7\Factory\Psr17Factory``
22+
- One factory can create plain PSR-17 responses
23+
* - ``Psr\Http\Message\ServerRequestFactoryInterface``
24+
- ``Nyholm\Psr7\Factory\Psr17Factory``
25+
- One factory can create server requests manually
26+
* - ``Psr\Http\Message\StreamFactoryInterface``
27+
- ``Nyholm\Psr7\Factory\Psr17Factory``
28+
- One factory can create plain PSR-17 streams
29+
* - ``Psr\Http\Message\UploadedFileFactoryInterface``
30+
- ``Nyholm\Psr7\Factory\Psr17Factory``
31+
- One factory can create uploaded files
32+
* - ``Psr\Http\Message\UriFactoryInterface``
33+
- ``Nyholm\Psr7\Factory\Psr17Factory``
34+
- One factory can create URIs
35+
* - ``Nyholm\Psr7Server\ServerRequestCreatorInterface``
36+
- ``Nyholm\Psr7Server\ServerRequestCreator``
37+
- You code against the interface instead of the concrete class
38+
* - ``FastForward\Http\Message\Factory\ResponseFactoryInterface``
39+
- ``FastForward\Http\Message\Factory\ResponseFactory``
40+
- Adds convenience methods for common response types
41+
* - ``FastForward\Http\Message\Factory\StreamFactoryInterface``
42+
- ``FastForward\Http\Message\Factory\StreamFactory``
43+
- Adds payload-aware stream creation
44+
45+
What This Means In Practice
46+
---------------------------
47+
48+
- All PSR-17 factory interfaces resolve to the same underlying ``Psr17Factory`` instance in the
49+
default container setup.
50+
- You can type-hint the standard interfaces in your own services and stay decoupled from concrete
51+
implementations.
52+
- You can request the Fast Forward convenience interfaces when you want extra helper methods that
53+
do not exist in the PSR interfaces.
54+
55+
Provider Instances Are Also Registered
56+
--------------------------------------
57+
58+
Because ``HttpServiceProvider`` extends ``AggregateServiceProvider``, the following provider
59+
instances are also available by class name:
60+
61+
- ``FastForward\Http\ServiceProvider\HttpServiceProvider``
62+
- ``FastForward\Http\Message\Factory\ServiceProvider\HttpMessageFactoryServiceProvider``
63+
- ``FastForward\Http\Client\ServiceProvider\HttpClientServiceProvider``
64+
65+
This is mostly useful for inspection, debugging, or advanced composition, not for day-to-day
66+
application code.

docs/advanced/customization.rst

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Customization
2+
=============
3+
4+
The default configuration is intentionally simple, but you can replace or narrow parts of the stack
5+
when your application needs different defaults.
6+
7+
Use Only The Underlying Provider You Need
8+
-----------------------------------------
9+
10+
If you only need factories, you can register the message factory provider directly instead of the
11+
full aggregate provider:
12+
13+
.. code-block:: php
14+
15+
<?php
16+
17+
declare(strict_types=1);
18+
19+
use FastForward\Http\Message\Factory\ServiceProvider\HttpMessageFactoryServiceProvider;
20+
use function FastForward\Container\container;
21+
22+
$container = container(new HttpMessageFactoryServiceProvider());
23+
24+
If you need only the client provider, register ``HttpClientServiceProvider`` directly.
25+
26+
Override A Service With Your Own Provider
27+
-----------------------------------------
28+
29+
The easiest way to replace one of the default services is to register your own provider *before*
30+
``HttpServiceProvider``. The aggregate container resolves identifiers in registration order, so the
31+
first matching provider wins.
32+
33+
.. code-block:: php
34+
35+
<?php
36+
37+
declare(strict_types=1);
38+
39+
use FastForward\Http\ServiceProvider\HttpServiceProvider;
40+
use Interop\Container\ServiceProviderInterface;
41+
use Psr\Container\ContainerInterface;
42+
use Psr\Http\Client\ClientInterface;
43+
use Psr\Http\Message\ResponseFactoryInterface;
44+
use Psr\Http\Message\StreamFactoryInterface;
45+
use Symfony\Component\HttpClient\HttpClient;
46+
use Symfony\Component\HttpClient\Psr18Client;
47+
use function FastForward\Container\container;
48+
49+
final class CustomHttpClientServiceProvider implements ServiceProviderInterface
50+
{
51+
public function getFactories(): array
52+
{
53+
return [
54+
HttpClient::class => static fn() => HttpClient::create([
55+
'timeout' => 5.0,
56+
]),
57+
ClientInterface::class => static fn(ContainerInterface $container) => new Psr18Client(
58+
$container->get(HttpClient::class),
59+
$container->get(ResponseFactoryInterface::class),
60+
$container->get(StreamFactoryInterface::class),
61+
),
62+
];
63+
}
64+
65+
public function getExtensions(): array
66+
{
67+
return [];
68+
}
69+
}
70+
71+
$container = container(
72+
new CustomHttpClientServiceProvider(),
73+
new HttpServiceProvider(),
74+
);
75+
76+
What You Can Replace Safely
77+
---------------------------
78+
79+
- ``Psr\Http\Client\ClientInterface`` if you want a different PSR-18 client
80+
- ``Symfony\Component\HttpClient\HttpClient`` if you want different Symfony client defaults
81+
- any PSR-17 factory interface if you need different object creation rules
82+
- the Fast Forward convenience factory interfaces if you want different helper behavior
83+
84+
When Not To Customize
85+
---------------------
86+
87+
Avoid replacing services just to reach the defaults. If the default behavior already matches your
88+
needs, prefer the stock provider because it keeps application bootstrap code shorter and easier to
89+
understand.

docs/advanced/index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
Advanced
22
========
33

4-
This section covers advanced integration and extension topics for FastForward HTTP.
4+
This section explains how the package integrates with the Fast Forward container, how aliases work,
5+
and how to replace or narrow parts of the default HTTP stack when you need more control.
56

67
.. toctree::
78
:maxdepth: 1
89

910
integration
1011
aliases
12+
customization
13+
troubleshooting

docs/advanced/integration.rst

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,77 @@
11
Integration
22
===========
33

4-
FastForward HTTP is designed to work seamlessly with the FastForward Container and other FastForward packages. By aggregating service providers, it ensures all HTTP-related services are available in your dependency injection container.
4+
Fast Forward HTTP is designed to fit naturally into the Fast Forward container story, but the
5+
package remains useful anywhere service providers and PSR-11 containers are part of the
6+
application architecture.
57

6-
You can extend or override services by providing your own service providers to the container alongside or instead of the default ones.
8+
Registering With The ``container()`` Helper
9+
-------------------------------------------
10+
11+
.. code-block:: php
12+
13+
<?php
14+
15+
declare(strict_types=1);
16+
17+
use FastForward\Http\ServiceProvider\HttpServiceProvider;
18+
use function FastForward\Container\container;
19+
20+
$container = container(new HttpServiceProvider());
21+
22+
This is the most direct and beginner-friendly setup.
23+
24+
Registering Through Configuration
25+
---------------------------------
26+
27+
The Fast Forward container helper can also discover service providers from configuration.
28+
29+
.. code-block:: php
30+
31+
<?php
32+
33+
declare(strict_types=1);
34+
35+
use FastForward\Config\ArrayConfig;
36+
use FastForward\Container\ContainerInterface;
37+
use FastForward\Http\ServiceProvider\HttpServiceProvider;
38+
use function FastForward\Container\container;
39+
40+
$config = new ArrayConfig([
41+
ContainerInterface::class => [
42+
HttpServiceProvider::class,
43+
],
44+
]);
45+
46+
$container = container($config);
47+
48+
This is useful when your application already centralizes provider registration in configuration.
49+
50+
Working Alongside Other Providers
51+
---------------------------------
52+
53+
You can compose ``HttpServiceProvider`` with your own service providers or with providers from
54+
other Fast Forward packages.
55+
56+
.. code-block:: php
57+
58+
<?php
59+
60+
declare(strict_types=1);
61+
62+
use App\ServiceProvider\ApplicationServiceProvider;
63+
use FastForward\Http\ServiceProvider\HttpServiceProvider;
64+
use function FastForward\Container\container;
65+
66+
$container = container(
67+
new ApplicationServiceProvider(),
68+
new HttpServiceProvider(),
69+
);
70+
71+
General Integration Guidance
72+
----------------------------
73+
74+
- Use ``HttpServiceProvider`` when you want the full HTTP stack in one place.
75+
- Use the underlying providers directly when you only want factories or only want the client.
76+
- Keep your own services typed against PSR interfaces whenever possible.
77+
- Move to :doc:`customization` when you need to override the default implementations.

0 commit comments

Comments
 (0)