PHP code example of floopfloop / sdk

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

    

floopfloop / sdk example snippets



loopFloop\Client;

$client = new Client(apiKey: getenv('FLOOP_API_KEY'));

$created = $client->projects()->create([
    'prompt' => 'A landing page for a cat cafe',
    'subdomain' => 'cat-cafe',
    'botType' => 'site',
]);

$live = $client->projects()->waitForLive($created['project']['id']);
echo "Live at: {$live['url']}\n";

$client->projects()->stream('my-subdomain', function (array $event): void {
    echo "[{$event['status']}] step={$event['step']} progress={$event['progress']}\n";
});

use FloopFloop\Client;
use FloopFloop\Error;

try {
    $client->projects()->status('p_nonexistent');
} catch (Error $e) {
    if ($e->code === 'RATE_LIMITED') {
        sleep((int) ($e->retryAfter ?? 5));
        // retry ...
    }
    throw $e;
}

$client = new Client(
    apiKey: 'flp_...',
    baseUrl: 'https://staging.floopfloop.com',   // default: https://www.floopfloop.com
    timeout: 60.0,                                // default: 30.0 seconds
    userAgentSuffix: 'myapp/1.2.3',               // appended to floopfloop-php-sdk/<version>
);

use FloopFloop\HttpClient;
use FloopFloop\Client;

final class CurlHttpClient implements HttpClient { /* ... */ }

$client = new Client(apiKey: '...', httpClient: new CurlHttpClient());