定制 overtrue/http 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

overtrue/http

最新稳定版本:1.2.3

Composer 安装命令:

composer require overtrue/http

包简介

A simple http client wrapper.

README 文档

README

Http

🌵 A simple http client wrapper.

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

Sponsor me

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');

❤️ Sponsor me

Sponsor me

如果你喜欢我的项目并想支持它,点击这里 ❤️

Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT

统计信息

  • 总下载量: 324.4k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 128
  • 点击次数: 1
  • 依赖项目数: 36
  • 推荐数: 0

GitHub 信息

  • Stars: 127
  • Watchers: 6
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-12-20