|
1 | | -# Adapter Guzzle for CodeIgniter 4 |
| 1 | +# Support Adapter Guzzle for CodeIgniter 4 |
2 | 2 |
|
3 | | -Library ini menyediakan integrasi **Adapter Guzzle** dengan framework **CodeIgniter 4**. |
4 | | -Membantu developer dengan mudah melalui Service Facade. |
| 3 | +Support Adapter is a lightweight package that provides a Guzzle HTTP Adapter with a flexible approach for both CodeIgniter 4 and standalone PHP projects. |
5 | 4 |
|
6 | | ---- |
| 5 | +Its main goal is to simplify HTTP communication with external APIs through the PSR-7 and PSR-18 standards, keeping your code clean, consistent, and testable. |
7 | 6 |
|
8 | 7 | ## 📦 Installation |
9 | 8 |
|
10 | 9 | 1. **Install via Composer** |
11 | 10 | ```bash |
12 | 11 | composer require reactmore/support-adapter |
13 | 12 | ``` |
| 13 | + |
| 14 | +## 📖 Example Usage |
| 15 | +```php |
| 16 | +use Reactmore\SupportAdapter\Adapter\Guzzle; |
| 17 | +use Reactmore\SupportAdapter\Adapter\Auth\None; |
| 18 | + |
| 19 | +// Auth adapter (no authentication) |
| 20 | +$auth = new None(); |
| 21 | + |
| 22 | +// Initialize the adapter |
| 23 | +$adapter = new Guzzle($auth, 'https://api.example.com/'); |
| 24 | + |
| 25 | +// Perform a GET request |
| 26 | +$response = $adapter->get('users'); |
| 27 | + |
| 28 | +// Get response body |
| 29 | +$data = json_decode($response->getBody()->getContents(), true); |
| 30 | + |
| 31 | + |
| 32 | +print_r($data); |
| 33 | + |
| 34 | +``` |
| 35 | + |
| 36 | +## 🚀 CodeIgniter 4 Integration |
| 37 | + |
| 38 | +With Support Adapter, you can register a service in app/Config/Services.php for dependency injection into your CodeIgniter 4 project: |
| 39 | + |
| 40 | +```php |
| 41 | +public static function apiClient($getShared = true) |
| 42 | +{ |
| 43 | + if ($getShared) { |
| 44 | + return static::getSharedInstance('apiClient'); |
| 45 | + } |
| 46 | + |
| 47 | + $auth = new \Reactmore\SupportAdapter\Adapter\Auth\None(); |
| 48 | + return new \Reactmore\SupportAdapter\Adapter\Guzzle($auth, 'https://api.example.com/'); |
| 49 | +} |
| 50 | + |
| 51 | +``` |
| 52 | +## 🤝 Contributing |
| 53 | + |
| 54 | +Contributions are always welcome! |
| 55 | + |
| 56 | +If you’d like to improve Support Adapter, here’s how you can help: |
| 57 | + |
| 58 | +``` |
| 59 | +1. Fork the repository |
| 60 | +2. Create a new feature branch (git checkout -b feature/my-new-feature) |
| 61 | +3. Commit your changes (git commit -m 'Add new feature') |
| 62 | +4. Push to the branch (git push origin feature/my-new-feature) |
| 63 | +5. Open a Pull Request |
| 64 | +``` |
0 commit comments