php-http/discovery
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The php-http/discovery package is a library that provides automated discovery and installation of renowned PSR-17, PSR-18, and HTTPlug implementations. This facilitates the use of these standard HTTP message interfaces in your PHP projects, simplifying the development process by allowing interoperability between different PHP libraries.
To use php-http/discovery, start by installing the package via Composer using the following command:
composer require php-http/discovery
Once installed, you can leverage php-http/discovery in your library or SDK. Here's a quick guide on how to use a PSR-18 client with the package:
First, install a PSR-18 client and a PSR-17 factory implementation as dev dependencies:
composer require --dev symfony/http-client
composer require --dev nyholm/psr7
Next, disable the Composer plugin embedded in php-http/discovery
using the following command:
composer config allow-plugins.php-http/discovery false
Then, add php-http/discovery
and the generic implementations your library requires:
composer require 'php-http/discovery:^1.17'
composer require 'psr/http-client-implementation:*'
composer require 'psr/http-factory-implementation:*'
Now, you can create an HTTP request as follows:
use Http\Discovery\Psr18Client;
$client = new Psr18Client();
$request = $client->createRequest('GET', 'https://example.com');
$response = $client->sendRequest($request);
The above code will utilize any PSR-7, PSR-17, and PSR-18 implementations that your users have installed in the background.
The comprehensive documentation for php-http/discovery can be found on the official PHP-HTTP documentation site. The documentation provides deeper insights into using the package, including usage as both a library author and a library user.