2017 © Pedro Peláez
 

library http

A simple http client wrapper.

image

overtrue/http

A simple http client wrapper.

  • Wednesday, March 7, 2018
  • by overtrue
  • Repository
  • 4 Watchers
  • 62 Stars
  • 585 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 4 Versions
  • 8 % Grown

The README.md

, (*1)

Http

:cactus: A simple http client wrapper., (*2)

Build Status Latest Stable Version Latest Unstable Version Build Status Scrutinizer Code Quality Total Downloads License , (*3)

Sponsor me, (*4)

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:, (*5)

$ composer require monolog/monolog

Add logger middleware:, (*6)

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

:heart: Sponsor me

Sponsor me, (*7)

如果你喜欢我的项目并想支持它,点击这里 :heart:, (*8)

Project supported by JetBrains

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

, (*10)

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?, (*11)

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

License

MIT, (*13)

The Versions

07/03 2018

dev-master

9999999-dev

A simple http client wrapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

07/03 2018

1.0.1

1.0.1.0

A simple http client wrapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

22/12 2017

1.0.0

1.0.0.0

A simple http client wrapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

19/12 2017

1.0.0-beta.1

1.0.0.0-beta1

A simple http client wrapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue