cherrynechou / http
A simple http client wrapper.
2.0.0
2021-09-15 05:54 UTC
Requires
- php: >=7.2|^8.0
- ext-curl: *
- ext-json: *
- ext-libxml: *
- ext-simplexml: *
- guzzlehttp/guzzle: ^7.2
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.7
- friendsofphp/php-cs-fixer: ^2.15
- mockery/mockery: ^1.0
- overtrue/phplint: ^2.0
- phpunit/phpunit: ^8.5
This package is not auto-updated.
Last update: 2024-11-07 19:08:42 UTC
README
Http
🌵 A simple http client wrapper.
Installing
$ composer require overtrue/http -vvv
Usage
<?php use Overtrue\Http\Client; $client = Client::create(); $response = $client->get('https://httpbin.org/ip'); //{ // "ip": "1.2.3.4" //}
Configuration:
use Overtrue\Http\Client; $config = [ 'base_uri' => 'https://www.easyhttp.com/apiV2/', 'timeout' => 3000, 'headers' => [ 'User-Agent' => 'MyClient/1.0', 'Content-Type' => 'application/json' ] //... ]; $client = Client::create($config); // or new Client($config); //...
Custom response type
$config = new Config([ 'base_uri' => 'https://www.easyhttp.com/apiV2/', // array(default)/collection/object/raw 'response_type' => 'collection', ]); //...
Logging request and response
Install monolog:
$ composer require monolog/monolog
Add logger middleware:
use Overtrue\Http\Client; $client = Client::create(); $logger = new \Monolog\Logger('my-logger'); $logger->pushHandler( new \Monolog\Handler\RotatingFileHandler('/tmp/my-log.log') ); $client->pushMiddleware(\GuzzleHttp\Middleware::log( $logger, new \GuzzleHttp\MessageFormatter(\GuzzleHttp\MessageFormatter::DEBUG) )); $response = $client->get('https://httpbin.org/ip');
PHP 扩展包开发
想知道如何从零开始构建 PHP 扩展包?
请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》
License
MIT