Skip to content

uchm4n/api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Client Wrapper

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);

About

Any API Wrapper client library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages