PHP code example of vitisstudio / restdb

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

    

vitisstudio / restdb example snippets


'legacy_api' => [
    'driver'   => 'restdb',
    'adapter'  => 'generic',
    'base_url' => env('LEGACY_URL'),
    'auth'     => ['driver' => 'bearer', 'token' => env('LEGACY_TOKEN')],
    'compiler'  => App\RestDB\LegacyCompiler::class,   // implements RequestCompiler
    'parser'    => App\RestDB\LegacyParser::class,     // implements ResponseParser
    'paginator' => App\RestDB\LegacyPaginator::class,  // optional; default: one page, ever
    'capabilities' => [                                // baseline is NONE — declare or it throws
        'select' => true,
        'filter' => ['operators' => ['eq', 'in']],
        'sort'   => true,
    ],
],

class Invoice extends Model
{
    use \Vitis\RestDB\Eloquent\InteractsWithRestApi;

    protected $connection = 'legacy_api';
    protected $table = 'invoices';
}

'http' => [
    'timeout' => 30,
    'connect_timeout' => 10,
    'retry' => [
        'times' => 1,      // attempts for connection failures
        'sleep' => 100,    // ms; also the throttle backoff floor
        'throttle' => [
            'times' => 3,      // extra retries granted to 429/503; 0 disables
            'max_wait' => 60,  // seconds; cap on any single throttle wait
        ],
    ],
],

'crm' => [
    'driver'   => 'restdb',
    'adapter'  => 'json-api',
    'base_url' => env('CRM_API_URL'),
    'http' => [
        'middleware' => [
            App\RestDB\CrmRateLimit::class,   // rate limiting
            App\RestDB\CrmCache::class,       // response caching
        ],
    ],
],

use Spatie\GuzzleRateLimiterMiddleware\RateLimiterMiddleware;

final class CrmRateLimit
{
    public function __invoke(callable $handler): callable
    {
        // Default store is in-memory (per process). For a limit shared across
        // web requests and queue workers, pass a Store backed by your cache.
        return RateLimiterMiddleware::perSecond(10)($handler);
    }
}

use Kevinrob\GuzzleCache\CacheMiddleware;
use Kevinrob\GuzzleCache\Storage\LaravelCacheStorage;
use Kevinrob\GuzzleCache\Strategy\GreedyCacheStrategy;

final class CrmCache
{
    public function __invoke(callable $handler): callable
    {
        return (new CacheMiddleware(
            new GreedyCacheStrategy(
                new LaravelCacheStorage(cache()->store()),
                300, // seconds
            ),
        ))($handler);
    }
}