Skip to content
🌵 A simple http client wrapper.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Merge pull request #11 from mingyoung/patch-1 Jan 13, 2019
tests init commit. Dec 19, 2017
.editorconfig init commit. Dec 19, 2017
.gitattributes init commit. Dec 19, 2017
.gitignore Travis CI. Nov 27, 2018
.php_cs init commit. Dec 19, 2017
.travis.yml Travis CI. Nov 27, 2018
README.md Update README.md Apr 5, 2019
composer.json Update phpunit/phpunit requirement from ^6.5 to ^6.5 || ^8.0 Mar 28, 2019
phpunit.xml.dist init commit. Dec 19, 2017

README.md

Http

🌵 A simple http client wrapper.

Build Status Latest Stable Version Latest Unstable Version Build Status Scrutinizer Code Quality Code Coverage Total Downloads License

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,
    //'connect_timeout' => 3000,
];

$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

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

You can’t perform that action at this time.