aedart / athenaeum-http-clients
Http Client wrapper along with a Manager that is able to handle multiple client instances (profiles)
Requires
- php: ^8.2
- aedart/athenaeum-container: ^8.14
- aedart/athenaeum-contracts: ^8.14
- aedart/athenaeum-http-cookies: ^8.14
- aedart/athenaeum-http-messages: ^8.14
- aedart/athenaeum-support: ^8.14
- guzzlehttp/guzzle: ^7.9.2
- illuminate/pipeline: ^v11.31.0
- 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.14.0
- 8.13.0
- 8.12.0
- 8.11.0
- 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-11-13 10:28:29 UTC
README
This package offers a Http Client wrapper, with a powerful fluent request builder that is able to use different Http Query grammars, supporting both Json Api and OData. In addition, it also comes with a manager that allows you to handle multiple http client "profiles". This allows you to segment each api you communicate with, into it's own client instance.
Guzzle Http Client is used behind the scene.
Example
Configuration
return [ 'profiles' => [ 'my-client' => [ 'driver' => \Aedart\Http\Clients\Drivers\JsonHttpClient::class, 'options' => [ 'base_uri' => 'https://acme.com/api/v2' ] ], ] // ... remaining not shown ... ];
Usage
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 } }
Motivation
A Http Client "package" was made available in version 3.x of the Athenaeum library. It offered the manager to handle multiple "profiles" and some fluent methods for gradually building a request. But it was not as comprehensive as the current version. When Laravel released it's v7.x version, it came with a custom Http Client. Therefore, this package became somewhat irrelevant and was considered for deprecation. Ultimately, I decided to redesign this package entirely, mixing some of the already provided features with lots of new ones.
As a result, this package now draws inspiration from both Laravel's Http Client, as well as the Database Query Builder. You will find many similarities between the client offered by Laravel, and the one provided by this package. The intent isn't to copy Laravel's Http Client, but rather to provide a slightly different approach on request building.
When considering whether to use this Http Client, Laravel's or other Http Client, then it's probably best to stick with what you feel most comfortable with. To put a different perspective on this matter, consider that Laravel has a far better support for their packages, than I can currently offer.
Documentation
Please read the official documentation for additional information.
Repository
The mono repository is located at github.com/aedart/athenaeum
Versioning
This package follows Semantic Versioning 2.0.0
License
BSD-3-Clause, Read the LICENSE file included in this package