agsystemspl / abstract-rest-client
PHP (Guzzle) API Wrapper
Package info
github.com/agsystemspl/abstract-rest-client
pkg:composer/agsystemspl/abstract-rest-client
Requires
- php: >=7.0
- guzzlehttp/guzzle: ^6.0|^7.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-17 15:06:48 UTC
README
Overview
A PHP (Guzzle) API Wrapper designed for simplicity and extensibility. This library provides an elegant, fluent, chainable interface for constructing complex API endpoints and handling various HTTP methods.
Features
- π Fluent, chainable API design
- π Supports GET, POST, PUT, PATCH, DELETE, HEAD methods
- π§ Highly customizable and extensible
- π Safe URL encoding and path construction
- π¦ Flexible options management
- π Built on top of Guzzle HTTP
Requirements
- PHP 7.0+
- Guzzle HTTP (^6.0 or ^7.0)
Installation
Install via Composer:
composer require agsystemspl/abstract-rest-client
Basic Usage
Extending the Abstract Client
use AGSystemsPl\RestClient\AbstractClient; class MyApiClient extends AbstractClient { protected function clientOptions(): array { return [ 'base_uri' => 'https://api.example.com/v1/' ]; } } $client = new MyApiClient(); // Fluent path and method chaining $response = $client->users->123->get(['format' => 'json']);
Key Concepts
Path Construction
- Use property access or method calls to build paths
- Segments are automatically URL-encoded
- Null, false, and empty values are filtered out
Request Methods
// GET request $client->users->get(); // POST request with JSON body $client->users->post(['name' => 'John']); // PUT request $client->users->123->put(['name' => 'Updated']); // DELETE request $client->users->123->delete();
Options Management
// Set initial options $client = new MyApiClient([ 'timeout' => 10, 'verify' => false ]); // Replace all options $client->withOptions(['new' => 'configuration']); // Merge additional options $client->appendOptions(['extra' => 'settings']);
Advanced Customization
Extend the abstract class to add custom behavior:
class MyCustomClient extends AbstractClient { // Override path handling protected function handlePath($segments): string { // Custom path processing logic return parent::handlePath($segments); } // Custom response processing protected function handleResponse($response) { // Custom logic, e.g., XML parsing return $response; } }
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE for more information.
Contact
agsystems.pl - https://agsystems.pl
Project Link: https://github.com/agsystemspl/abstract-rest-client