PHP code example of uchm4n / api-client

1. Go to this page and download the library: Download uchm4n/api-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

uchm4n / api-client example snippets




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