PHP code example of teoprayoga / teobiefy-laravel-api-response
1. Go to this page and download the library: Download teoprayoga/teobiefy-laravel-api-response 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/ */
teoprayoga / teobiefy-laravel-api-response example snippets
return api()->ok('Success message', $data);
return api()->response(400, 'Bad request', $errors);
return api()->validation('Validation failed', $errors);
return api()->notFound();
return api()->forbidden();
return api()->error();
'response' => [
'default_profile' => 'plain',
'route_profiles' => [
'api/v1/users/*' => 'encrypted',
'api/v1/reports/*' => 'compressed_encrypted',
],
],
'request' => [
'default_profile' => 'plain',
'route_profiles' => [
'api/v1/auth/*' => 'encrypted',
],
],
use Teoprayoga\TeobiefyLaravelApiResponse\Attributes\RequestProfile;
use Teoprayoga\TeobiefyLaravelApiResponse\Attributes\ResponseProfile;
use Teoprayoga\TeobiefyLaravelApiResponse\Profile;
#[RequestProfile(Profile::ENCRYPTED)]
class UserController
{
#[ResponseProfile(Profile::COMPRESSED_ENCRYPTED)]
public function show(int $id) { /* ... */ }
}
'encryption' => [
'driver' => 'xchacha20-poly1305',
'key' => env('TEOBIEFY_ENCRYPTION_KEY'), // legacy fallback
'keys' => [
'v1' => env('TEOBIEFY_ENCRYPTION_KEY_V1'),
'v2' => env('TEOBIEFY_ENCRYPTION_KEY_V2'),
],
'active' => env('TEOBIEFY_ENCRYPTION_ACTIVE_KID'), // e.g. 'v2'
],
'signing' => [
'algorithm' => 'hmac-sha256',
'key' => env('TEOBIEFY_SIGNING_KEY'), // legacy fallback
'keys' => [
'v1' => env('TEOBIEFY_SIGNING_KEY_V1'),
],
'active' => env('TEOBIEFY_SIGNING_ACTIVE_KID'),
],
'replay_protection' => [
'enabled' => env('TEOBIEFY_REPLAY_PROTECTION', false),
'cache_store' => null, // null = default cache
'cache_prefix' => 'teobiefy:rp:',
'window_seconds' => 300,
'nonce_ttl_seconds' => 600, // must be >= 2 * window_seconds
],
'compression' => [
'driver' => 'zstd', // zstd or none
'level' => 3,
'min_bytes' => 1024,
'max_decompressed_bytes' => 10485760,
],
'encryption' => [
'driver' => 'xchacha20-poly1305',
'key' => env('TEOBIEFY_ENCRYPTION_KEY'),
'allow_sodium_compat_fallback' => false,
],
bash
php artisan vendor:publish --tag=api-response
bash
php artisan vendor:publish --tag=api-response-lang
bash
php artisan teobiefy:signing-key
bash
php artisan teobiefy:key