PHP code example of trivolink / unified-api

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

    

trivolink / unified-api example snippets


Route::middleware(['auth:sanctum', ...]) // was: 'auth'

'token_endpoint' => [
    'enabled' => env('UNIFIED_API_TOKEN_ENDPOINT', true),
    'path' => env('UNIFIED_API_TOKEN_PATH', 'api/token'),
    'middleware' => ['throttle:5,1'],
],

->withMiddleware(function (Middleware $middleware) {
    $middleware->validateCsrfTokens(except: [
        // ... your existing exceptions
    ]);
    // Laravel 13+ (the web group ships PreventRequestForgery):
    $middleware->replaceInGroup(
        'web',
        \Illuminate\Foundation\Http\Middleware\PreventRequestForgery::class,
        \TrivoLink\UnifiedApi\Middleware\ValidateCsrfTokenExceptApiClients::class,
    );
    // On Laravel 11-12, target ValidateCsrfToken::class instead.
})

$this->get('/dashboard', ['Accept' => 'application/json'])
    ->assertOk()
    ->assertJsonPath('version', 'v1')
    ->assertJsonPath('data.users', 5);

use function envelopeSnapshot; // global helper, autoloaded

test('dashboard envelope contract', function () {
    $user = User::factory()->create();

    envelopeSnapshot('dashboard', fn () => $this
        ->actingAs($user)
        ->get(route('dashboard'), ['Accept' => 'application/json']));
});
bash
php artisan vendor:publish --tag=unified-api-config