trulyao / neat-http
基于cURL的HTTP客户端/包装器
1.0.0
2022-09-01 18:02 UTC
Requires
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.5.24
This package is auto-updated.
Last update: 2024-09-29 06:20:32 UTC
README
实验性
这是一个基于cURL的HTTP客户端。这是一个实验性副项目,如果你需要更健壮和稳定的解决方案,可以查看GuzzleHTTP。也欢迎你fork或提交PR哦 :)
要求
- PHP 8.0+
- cURL扩展(在
PHP.INI
中启用)
安装
composer require trulyao/neat-http
使用方法
<?php use Trulyao\NeatHttp\Client; $client = new Client( [ 'baseUrl' => 'http://example.com', 'object' => true, // return object instead of array 'headers' => [ 'Content-Type' => 'application/json', 'Accept' => 'application/json', ], ] // optional base config ); $variable1 = $client->get('1'); $variable2 = $client->post('', [ 'data' => [ 'title' => 'foo', 'body' => 'bar', 'userId' => 1, ], ]); // automatically serialized to JSON before sending
查看
__tests__
以获取更多使用示例。