https://github.com/decodelabs/hydro
Simple HTTP client wrapper around Guzzle
https://github.com/decodelabs/hydro
client http php
Last synced: 10 days ago
JSON representation
Simple HTTP client wrapper around Guzzle
- Host: GitHub
- URL: https://github.com/decodelabs/hydro
- Owner: decodelabs
- License: mit
- Created: 2023-10-16T13:30:58.000Z (over 2 years ago)
- Default Branch: develop
- Last Pushed: 2025-06-06T14:24:35.000Z (10 months ago)
- Last Synced: 2025-06-06T14:45:34.570Z (10 months ago)
- Topics: client, http, php
- Language: PHP
- Homepage:
- Size: 47.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Hydro
[](https://packagist.org/packages/decodelabs/hydro)
[](https://packagist.org/packages/decodelabs/hydro)
[](https://packagist.org/packages/decodelabs/hydro)
[](https://github.com/decodelabs/hydro/actions/workflows/integrate.yml)
[](https://github.com/phpstan/phpstan)
[](https://packagist.org/packages/decodelabs/hydro)
### Simple HTTP client wrapper around Guzzle
Hydro provides a simple interface to common HTTP client functionality using Guzzle under the hood.
---
## Installation
Install via Composer:
```bash
composer require decodelabs/hydro
```
## Usage
Basic usage for different types of files:
```php
use DecodeLabs\Hydro;
$memoryFile = Hydro::get('https://example.com/file.txt'); // Atlas file
$string = Hydro::getString('https://example.com/file.txt'); // String
$file = Hydro::getFile('https://example.com/file.txt', '/path/to/save/file.txt'); // Local file
$tempFile = Hydro::getTempFile('https://example.com/file.txt'); // Temp file
$json = Hydro::getJson('https://example.com/file.json'); // Decoded JSON array
$tree = Hydro::getJsonTree('https://example.com/file.json'); // Decoded JSON Collections/Tree
```
### Options
Pass an array of options (including URL) to the underlying client:
```php
Hydro::get([
'url' => 'https://example.com/file.txt',
'timeout' => 10
]);
```
### Errors
Handle error status responses (or return alternative response):
```php
$file = Hydro::get('https://example.com/file.txt', function($response) {
switch($response->getStatusCode()) {
case 404:
throw Exceptional::Notfound(
message: 'File not found'
);
case 500:
throw Exceptional::Runtime(
message: 'Server error'
);
default:
return Hydro::request('GET', 'https://example.com/other.txt');
}
});
```
## Licensing
Hydro is licensed under the proprietary License. See [LICENSE](./LICENSE) for the full license text.