Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sunrise-php/http-client-curl
Simple HTTP cURL client for PHP 7.1+ based on PSR-18
https://github.com/sunrise-php/http-client-curl
curl http http-client php-library php7 php8 psr-17 psr-18 psr-2 psr-7
Last synced: 3 months ago
JSON representation
Simple HTTP cURL client for PHP 7.1+ based on PSR-18
- Host: GitHub
- URL: https://github.com/sunrise-php/http-client-curl
- Owner: sunrise-php
- License: mit
- Created: 2019-01-18T15:43:42.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-24T08:15:03.000Z (9 months ago)
- Last Synced: 2024-04-24T14:17:15.496Z (9 months ago)
- Topics: curl, http, http-client, php-library, php7, php8, psr-17, psr-18, psr-2, psr-7
- Language: PHP
- Homepage:
- Size: 60.5 KB
- Stars: 16
- Watchers: 4
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple HTTP cURL client for PHP 7.1+ based on PSR-18
[![Build Status](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/badges/build.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/build-status/master)
[![Code Coverage](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/?branch=master)
[![Total Downloads](https://poser.pugx.org/sunrise/http-client-curl/downloads?format=flat)](https://packagist.org/packages/sunrise/http-client-curl)
[![Latest Stable Version](https://poser.pugx.org/sunrise/http-client-curl/v/stable?format=flat)](https://packagist.org/packages/sunrise/http-client-curl)
[![License](https://poser.pugx.org/sunrise/http-client-curl/license?format=flat)](https://packagist.org/packages/sunrise/http-client-curl)---
## Installation
```bash
composer require sunrise/http-client-curl
```## QuickStart
```bash
composer require sunrise/http-factory
``````php
use Sunrise\Http\Client\Curl\Client;
use Sunrise\Http\Factory\RequestFactory;
use Sunrise\Http\Factory\ResponseFactory;$client = new Client(new ResponseFactory());
$request = (new RequestFactory)->createRequest('GET', 'http://php.net/');
$response = $client->sendRequest($request);echo $response->getStatusCode(), PHP_EOL;
```### cURL options
> https://www.php.net/manual/ru/curl.constants.php
```php
$client = new Client(new ResponseFactory(), [
\CURLOPT_AUTOREFERER => true,
\CURLOPT_FOLLOWLOCATION => true,
]);
```### Parallel execution of multiple requests
```php
$requests = [
(new RequestFactory)->createRequest('GET', 'http://php.net/'),
(new RequestFactory)->createRequest('GET', 'http://php.net/'),
];$client = new Client(new ResponseFactory());
$responses = $client->sendRequests(...$request);foreach ($responses as $i => $response) {
// note that you can get the response's request by its index...
echo sprintf('%s => %d', $requests[$i]->getUri(), $response->getStatusCode()), PHP_EOL;
}
```---
## Test run
```bash
composer test
```## Useful links
* http://php.net/manual/en/intro.curl.php
* https://curl.haxx.se/libcurl/c/libcurl-errors.html
* https://www.php-fig.org/psr/psr-2/
* https://www.php-fig.org/psr/psr-7/
* https://www.php-fig.org/psr/psr-17/
* https://www.php-fig.org/psr/psr-18/