psr/http-client
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The psr/http-client package provides a common interface for HTTP clients in PHP. It defines abstractions that describe the components of an HTTP client but does not implement an HTTP client by itself. It serves to establish a standardized way of communicating with HTTP resources, and is particularly useful when you want to standardize or switch between different HTTP client implementations. By utilizing PSR-18, a part of PHP Standard Recommendations, this package makes sure your code remains clean and consistent across different projects.
The psr/http-client isn't a standalone package that you can directly use, but it's the basis on which compatible HTTP client libraries are built. To see its usage in action, you'd typically require a compatible HTTP client library in your PHP project using Composer, such as Guzzle or HttpPlug. Once the library is in place, here is a basic usage example:
<?php
use Psr\Http\Client\ClientInterface;
$client = new ClientInterface;
$request = new \Psr\Http\Message\RequestInterface(
'GET',
'https://api.example.com'
);
$response = $client->sendRequest($request);
echo $response->getBody();
This code instantiates an HTTP client, creates a new GET request to the example API, sends the request and finally outputs the response body.
You can find the documentation for the psr/http-client on the PHP-FIG website, specifically the PSR-18 documentation at https://www.php-fig.org/psr/psr-18. Additionally, detailed information about the package along with potential implementations can be found at https://packagist.org/packages/psr/http-client. Keep in mind that actual usage will depend on the HTTP client library you choose, so it's crucial to refer to their individual documentation for more specific guidance.