🌵 A simple http client wrapper.
$ composer require overtrue/http -vvv
<?php
use Overtrue\Http\Client;
$client = Client::create();
$response = $client->get('https://httpbin.org/ip');
//{
// "ip": "1.2.3.4"
//}
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);
//...
$config = new Config([
'base_uri' => 'https://www.easyhttp.com/apiV2/',
// array(default)/collection/object/raw
'response_type' => 'collection',
]);
//...
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');
如果你喜欢我的项目并想支持它,点击这里 ❤️
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
想知道如何从零开始构建 PHP 扩展包?
请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》
MIT