Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hanwenbo/fetch
easyswoole HttpClient
https://github.com/hanwenbo/fetch
Last synced: about 1 month ago
JSON representation
easyswoole HttpClient
- Host: GitHub
- URL: https://github.com/hanwenbo/fetch
- Owner: hanwenbo
- Created: 2022-03-08T13:13:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-08T06:50:12.000Z (about 2 years ago)
- Last Synced: 2024-04-26T01:43:28.313Z (8 months ago)
- Language: PHP
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 协程Http请求客户端
> 该类主要是为了解决第三方包用了guzzle基础请求方法保持一致,又能使用EasySwoole
## 安装
```
composer require hanwenbo/fetch
```
## 测试```
php tests/fetch.php
```> 要在`swoole` 环境下运行,根目录的 `docker-compose.yml` 是写项目经常用到的docker环境
> docker-compose up -d
> docker-compose exec swoole bash
> composer install
> php tests/fetch.php## 示例代码
#### GET
```php
$client = new \hanwenbo\fetch\Fetch();
$res = $client->request( 'GET', 'https://www.baidu.com', [
'header'=>[
'test'=>1
],
'query' => [
'adada' => 121212,
],
] );
```#### POST
> form请求
```php
$client = new \hanwenbo\fetch\Fetch();
$res = $client->request( 'POST', 'https://www.baidu.com', [
'header'=>[
'test'=>1
],
'form_params' => [
'adada' => 121212,
],
] );
```> json请求
```php
$client = new \hanwenbo\fetch\Fetch();
$res = $client->request( 'POST', 'https://www.baidu.com', [
'header'=>[
'test'=>1
],
'body' => [
'adada' => 121212,
],
] );
```> 其他的 `PUT` `DELETE` `PATCH` 参考 `POST` 即可
### 其他
- https://www.fashop.com/
- http://www.easyswoole.com/Components/httpClient.html
- https://github.com/easy-swoole/http-client
- https://guzzle-cn.readthedocs.io/zh_CN/latest/
- https://www.swoole.com/