rnr1721 / le7-http-client
PSR Http-client for le7 PHP MVC framework or any PSR project
1.0.1
2023-05-25 10:25 UTC
Requires
- php: >=8.1
- psr/http-client: *
- psr/http-factory: ^1.0
- psr/http-message: ^2.0
Requires (Dev)
- nyholm/psr7: ^1.8
- php-http/mock-client: ^1.6
- phpunit/phpunit: ^10.0
- rnr1721/psr7-server: ^1.0
- vimeo/psalm: ^5.7
Provides
README
Http client client for le7 PHP MVC framework or any PSR project This is an simple PSR http-client implementation
API Request Utility
This project provides HTTP clients that uses Curl and standard PHP functions to make requests.
What it can?
- Create HTTP requests using cURL
- Create HTTP requests using standard PHP tools
Requirements
- PHP 8.0 or higher
- Composer (for installing dependencies)
Installation
- Install via composer:
composer require rnr1721/le7-http-client
Testing
composer test
Usage
In this example, I use Nyholm PSR library, but you can use any, Guzzle for example
Get ClientInterface object (httpClient)
use Nyholm\Psr7\Factory\Psr17Factory; use Core\HttpClient\HttpClientCurl; use Core\HttpClient\HttpClientDefault; // Create PSR factories. Nyholm realisation is a single factory to all $psr17Factory = new Psr17Factory(); // Get Curl http client $httpClientCurl = new HttpClientCurl( $psr17Factory // ResponseFactoryInterface ) // Or if need get PHP http client $httpClientPhp = new HttpClientDefault( $psr17Factory // ResponseFactoryInterface ) // now we can use it: $request = $psr17Factory->createRequest('GET', 'http://tnyholm.se'); $response = $httpClientCurl->sendRequest($request);