PHP SDK - Installation#
rafikidb/rafikidb is a typed client for the RafikiDB API: data, auth,
realtime, storage, environment variables, secrets, webhooks, edge functions
and payments.
- PHP 8.1+, only
ext-curlandext-jsonrequired - Laravel-native: auto-discovered service provider, facade, config and auth guard
- Same envelope and error model as the REST API
Install#
composer require rafikidb/rafikidb
BashInitialize#
use RafikiDB\RafikiDB;
$db = RafikiDB::create(
projectId: '5c73dab0-...',
apiKey: 'raf_live_...',
baseUrl: 'https://api.rafikidb.com/api/v1', // optional
);
PHP| Option | Type | Description |
|---|---|---|
projectId | string | Required. Used by auth/realtime URLs |
apiKey | string | Required. Sent as X-AFRIBASE-API-Key |
baseUrl | ?string | Default http://localhost:8080/api/v1 |
Responses#
Every call returns the API envelope unchanged:
$rows = $db->from('profiles')->select('id')->limit(10)->execute();
$rows->success; // true
$rows->message; // "Request was successful"
$rows->data; // array of rows
$rows->errors; // []
PHPFailures throw RafikiDBException:
use RafikiDB\RafikiDBException;
try {
$db->from('profiles')->insert([]);
} catch (RafikiDBException $e) {
$e->getMessage(); // "Nationality is required"
$e->status; // 400
$e->errorCode; // "invalid_input"
$e->errors; // ["Nationality is required"]
}
PHPLaravel#
The service provider is auto-discovered. Publish the config and set .env:
php artisan vendor:publish --tag=rafikidb-config
BashRAFIKIDB_PROJECT_ID=5c73dab0-...
RAFIKIDB_API_KEY=raf_live_...
RAFIKIDB_URL=http://localhost:8080/api/v1
RAFIKIDB_AUTH_GUARD=true
BashUse the facade:
use RafikiDB\Facades\RafikiDB;
$rows = RafikiDB::from('messages')->select('id, message')->limit(10)->execute();
PHPAuth guard#
Register the guard and provider in config/auth.php:
'guards' => [
'rafikidb' => ['driver' => 'session', 'provider' => 'rafikidb'],
// ...existing guards
],
'providers' => [
'rafikidb' => ['driver' => 'rafikidb'],
// ...existing providers
],
PHPSign users in through the SDK and let the guard resolve them:
$result = RafikiDB::auth()->login($request->email, $request->password);
if ($result->success) {
$request->session()->regenerate();
return redirect()->intended('/dashboard');
}
$user = auth()->user(); // the project user
$user->full_name; // magic accessors
$user->rafikidbUser(); // the raw user array
PHPThe guard reads the SDK session; it does not verify passwords itself.
Next: Data.