Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/overtrue/http
:cactus: A simple http client wrapper.
https://github.com/overtrue/http
guzzlehttp http http-client sdk-client sdk-php
Last synced: 15 days ago
JSON representation
:cactus: A simple http client wrapper.
- Host: GitHub
- URL: https://github.com/overtrue/http
- Owner: overtrue
- Created: 2017-12-19T14:49:46.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-13T21:58:29.000Z (over 1 year ago)
- Last Synced: 2024-09-07T20:26:07.786Z (2 months ago)
- Topics: guzzlehttp, http, http-client, sdk-client, sdk-php
- Language: PHP
- Homepage:
- Size: 76.2 KB
- Stars: 126
- Watchers: 8
- Forks: 17
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
Http
:cactus: A simple http client wrapper.
[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue)
## Installing
```shell
$ composer require overtrue/http -vvv
```## Usage
```php
get('https://httpbin.org/ip');
//{
// "ip": "1.2.3.4"
//}
```### Configuration:
```php
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
```php
$config = new Config([
'base_uri' => 'https://www.easyhttp.com/apiV2/',
// array(default)/collection/object/raw
'response_type' => 'collection',
]);//...
```### Logging request and response
Install monolog:
```bash
$ composer require monolog/monolog
```
Add logger middleware:```php
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](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue)
如果你喜欢我的项目并想支持它,[点击这里 :heart:](https://github.com/sponsors/overtrue)
## Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/overtrue)
## PHP 扩展包开发
> 想知道如何从零开始构建 PHP 扩展包?
>
> 请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package)## License
MIT