PHP code example of star-insure / api-client

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

    

star-insure / api-client example snippets


StarApi::get('/users/me');
StarApi::get('/users');

Route::get('/protected', function () {
    return 'Only authenticated users can see this.';
})->middleware('auth');

Route::middleware(['auth'])->group(function () {
    Route::get('/protected', function () {
        return "Only authenticated users can see this.";
    });
});


// We use this helper purely to help the IDE recognise the global function's return type
if (! function_exists('auth') && isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] === 'ide') {
    /**
     * Get the available auth instance.
     */
    function auth(): StarInsure\Api\StarAuthManager
    {
        return new \StarInsure\Api\StarAuthManager(
            app(),
            config('star.api_url').'/api/'.config('star.version'),
        );
    }
}

if (! function_exists('api')) {
    /**
     * Global helper to create an instance of the StarApi client.
     */
    function api(string $token = null)
    {
        return new \StarInsure\Api\StarApi(
            auth_strategy: config('star.auth_strategy'),
            version: config('star.version'),
            apiTokenOverride: $token,
        );
    }
}

if (! function_exists('appApi')) {
    /**
     * An instance of the API client for non-authenticated routes
     */
    function appApi()
    {
        return new \StarInsure\Api\StarApi(
            'app',
            config('star.version'),
            config('star.token'),
            config('star.group_id')
        );
    }
}



$user = auth()->user();
$id = auth()->id();
$group = auth()->group();
$role = auth()->role();
$permissions = auth()->permissions();
$context = auth()->context();

$apiResponse = api()->get('/users/me', [ '
sh
php artisan vendor:publish --tag=starinsure
sh
json
"autoload": {
    ...
    "files": [
        "app/helpers.php"
    ]
},

composer dump-autoload