aedart / athenaeum-http-clients
Http 客户端包装器,附带一个能够处理多个客户端实例(配置文件)的管理器
Requires
- php: ^8.2
- aedart/athenaeum-container: ^8.10
- aedart/athenaeum-contracts: ^8.10
- aedart/athenaeum-http-cookies: ^8.10
- aedart/athenaeum-http-messages: ^8.10
- aedart/athenaeum-support: ^8.10
- guzzlehttp/guzzle: ^7.9.2
- illuminate/pipeline: ^v11.23.5
- psr/http-client: ^1.0.3
- psr/http-factory: ^1.1.0
- psr/http-message: ^1.1
- shrikeh/teapot: ^2.3.1
Suggests
- illuminate/log: Required for logging requests / response
- symfony/var-dumper: Required for using debugging utilities
- dev-main
- 8.10.0
- 8.9.0
- 8.8.0
- 8.7.0
- 8.6.0
- 8.5.0
- 8.4.0
- 8.3.0
- 8.2.0
- 8.1.0
- 8.0.0
- 7.33.0
- 7.32.0
- 7.31.0
- 7.30.1
- 7.30.0
- 7.29.0
- 7.28.0
- 7.27.0
- 7.26.0
- 7.25.0
- 7.24.0
- 7.23.0
- 7.22.1
- 7.22.0
- 7.21.0
- 7.20.0
- 7.19.0
- 7.18.1
- 7.18.0
- 7.17.0
- 7.16.0
- 7.15.0
- 7.14.0
- 7.13.0
- 7.12.0
- 7.11.3
- 7.11.2
- 7.11.1
- 7.11.0
- 7.10.1
- 7.10.0
- 7.9.1
- 7.9.0
- 7.8.0
- 7.7.2
- 7.7.1
- 7.7.0
- 7.6.0
- 7.5.0
- 7.4.0
- 7.3.0
- 7.2.0
- 7.1.0
- 7.0.1
- 7.0.0
- 7.0.0-alpha.1
- 6.8.1
- 6.8.0
- 6.7.0
- 6.6.0
- 6.5.2
- 6.5.1
- 6.5.0
- 6.4.0
- 6.3.0
- 6.2.1
- 6.2.0
- 6.1.1
- 6.1.0
- 6.0.2
- 6.0.1
- 6.0.0
- 5.27.0
- 5.26.0
- 5.25.0
- 5.24.2
- 5.24.1
- 5.24.0
- 5.23.0
- 5.22.4
- 5.22.3
- 5.22.2
- 5.22.1
- 5.22.0
- 5.21.0
- 5.20.0
- 5.19.0
- 5.18.1
- 5.18.0
- 5.17.0
- 5.16.0
- 5.15.0
- 5.14.1
- 5.14.0
- 5.13.2
- 5.13.1
- 5.13.0
- 5.12.0
- 5.11.0
- 5.10.1
- 5.10.0
- 5.9.0
- 5.8.0
- 5.7.0
- 5.6.0
- 5.5.1
- 5.5.0
- 5.4.0
- 5.3.5
- 5.3.4
- 5.3.3
- 5.3.2
- 5.3.1
- 5.3.0
- 5.2.1
- 5.2.0
- 5.1.0
- 5.0.2
- 5.0.1
- 5.0.0
- 4.2.1
- 4.2.0
- 4.1.0
- 4.0.1
- v4.0
This package is auto-updated.
Last update: 2024-09-23 07:55:59 UTC
README
此包提供Http客户端包装器,具有强大的流畅请求构建器,能够使用不同的Http查询语法,支持Json Api和OData。此外,它还附带一个管理器,允许您处理多个http客户端"配置文件"。这使得您可以将与每个api通信的每个部分分割成它自己的客户端实例。
在幕后使用Guzzle Http Client。
示例
配置
return [ 'profiles' => [ 'my-client' => [ 'driver' => \Aedart\Http\Clients\Drivers\JsonHttpClient::class, 'options' => [ 'base_uri' => 'https://acme.com/api/v2' ] ], ] // ... remaining not shown ... ];
用法
use Aedart\Http\Clients\Traits\HttpClientsManagerTrait; use Aedart\Contracts\Http\Clients\Responses\Status; use Teapot\StatusCode; use DateTime; class CurrencyController { use HttpClientsManagerTrait; public function index() { $client = $this->getHttpClientsManager()->profile('my-client'); // Perform a GET request $response = $client ->useTokenAuth('my-secret-api-token') ->where('currency', 'DKK') ->whereDate('date', new DateTime('now')) ->expect(StatusCode::OK, function(Status $status){ throw new RuntimeException('API is not available: ' . $status); }) ->get('/currencies'); // ...remaining not shown } }
动机
A Http Client "包"在Athenaeum库的3.x版本中提供。它提供了管理器来处理多个"配置文件"和一些用于逐步构建请求的流畅方法。但它不如当前版本全面。当Laravel发布v7.x版本时,它附带了一个自定义的Http Client。因此,这个包变得有些不相关,并被认为是弃用的。最终,我决定完全重新设计这个包,将一些已经提供的功能与新功能相结合。
因此,此包现在从Laravel的Http Client以及数据库查询构建器中汲取灵感。您将在Laravel提供的客户端和此包提供的客户端之间找到许多相似之处。意图并不是复制Laravel的Http Client,而是提供一种不同的请求构建方法。
在考虑是否使用此Http Client、Laravel或其他Http Client时,可能最好坚持使用您最舒适的方法。从不同角度看待这个问题,考虑一下,Laravel对其包的支持远比我目前能提供的要好。
文档
请阅读官方文档以获取更多信息。
存储库
单仓库位于github.com/aedart/athenaeum
版本控制
此包遵循语义版本控制2.0.0
许可
BSD-3-Clause,阅读包含在此包中的LICENSE文件