uchm4n / api-client
Any API Wrapper client library
1.0.2
2021-12-03 21:03 UTC
Requires
- php: ^7.4|^8.1
- guzzlehttp/guzzle: ^7.4
- pestphp/pest: ^1.21
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Seamlessly integrate REST APIs into your PHP projects.
This is a lightweight, framework-agnostic package designed to wrap any API with minimal effort. Built on top of Guzzle, it eliminates boilerplate code, allowing you to focus on data rather than HTTP handshake mechanics.
Below is an example demonstrating integration with the JSONPlaceholder API.
Features
- 🚀 Framework Agnostic: Works with Laravel, Symfony, or vanilla PHP.
- âš¡ Guzzle Powered: Leverages the robustness of the Guzzle HTTP client.
- 🔌 Plug & Play: Designed for instant integration and rapid prototyping.
Installation
composer require uchm4n/api-client
Usage
<?php require_once 'vendor/autoload.php'; use uchm4n\APIClient; $api = new APIClient(); // 1. Fetch all resources $posts = $api->getPosts(); // 2. Fetch a specific resource $post = $api->getPostByID(1); // 3. Fetch resources with relationships $postWithComments = $api->getPostWithComments(1); $comments = $api->getCommentsByPost(5); // 4. Create a new resource (POST) $api->savePost([ 'title' => 'New Entry', 'body' => 'Content goes here...', 'userId' => 1, ]); // 5. Update a resource (PUT) $api->updatePost([ 'id' => 1, 'title' => 'Updated Title', 'body' => 'Updated content...', 'userId' => 1, ]); // 6. Partial update (PATCH) $api->patchPost([ 'id' => 1, 'title' => 'Patched Title', ]); // 7. Delete a resource $api->deletePost(5);