PHP code example of anper / jsonbox

1. Go to this page and download the library: Download anper/jsonbox 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/ */

    

anper / jsonbox example snippets


use Anper\Jsonbox\Jsonbox;

$jsonbox = Jsonbox::factory('box-id');

// Create a record
$response = $jsonbox->create(['name' => 'Arya Stark']);

// Create multiple records
$response = $jsonbox->create([
    ['name' => 'Daenerys Targaryen'],
    ['name' => 'Arya Stark'],
]);

// Create a collection
$response = $jsonbox->colletion('users')
    ->create(/* like one record or multiple records */);   

// Read a record
$response = $jsonbox->record('5d776a25fd6d3d6cb1d45c51')->read();

// Read a collection
$response = $jsonbox->collection('users')->read();

// Read all
$response = $jsonbox->read();

$filter = new \Anper\Jsonbox\Filter();
$filter->equalTo('name', 'Arya Stark');

// Filter all
$response = $jsonbox->read($filter);

// Filter collection
$response = $jsonbox->collection('users')->read($filter);

// Update a record
$response = $jsonbox->record('5d776a25fd6d3d6cb1d45c51')
    ->update(['name' => 'Arya Stark']);

// Update multiple records (async request for every record)
$response = $jsonbox->update([
    '5d776b75fd6d3d6cb1d45c52' => ['name' => 'Daenerys Targaryen'],
    '5d776b75fd6d3d6cb1d45c53' => ['name' => 'Arya Stark'],
]);

// Delete a record
$response = $jsonbox->record('5d776a25fd6d3d6cb1d45c51')->delete();

// Delete multiple records (async request for every record)
$response = $jsonbox->delete([
    '5d776b75fd6d3d6cb1d45c52',
    '5d776b75fd6d3d6cb1d45c53',
]);

// Delete by filter
$response = $jsonbox->delete($filter);

// An API-KEY should be a valid GUID/UUID
$protectedJsonbox = $jsonbox->withApiKey('API_KEY');