PHP code example of bitshost / php-crud-api-generator
1. Go to this page and download the library: Download bitshost/php-crud-api-generator 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/ */
bitshost / php-crud-api-generator example snippets
return [
'host' => 'localhost',
'dbname' => 'your_database',
'user' => 'your_db_user',
'pass' => 'your_db_password',
'charset' => 'utf8mb4',
];
return [
'auth_enabled' => true,
'auth_method' => 'jwt', // apikey | basic | jwt (oauth = not implemented)
'api_keys' => ['use-long-random-keys'],
'api_key_role' => 'readonly',
'basic_users' => ['admin' => 'change-me'],
'jwt_secret' => 'generate-with-random_bytes-32+',
'jwt_issuer' => 'yourdomain.com',
'jwt_audience' => 'yourdomain.com',
// Empty allowlist = all except denied. Non-empty = whitelist only.
'allowed_tables' => [], // e.g. ['users', 'orders']
'denied_tables' => ['api_users', 'api_key_usage'],
'rate_limit' => [
'enabled' => true,
'max_requests' => 100,
'window_seconds' => 60,
],
'logging' => [
'enabled' => true,
'log_dir' => __DIR__ . '/../logs',
'log_level' => 'info',
],
];
bash
composer create-project bitshost/php-crud-api-generator my-api
cd my-api
php scripts/install-config.php .
notepad config/db.php
notepad config/api.php
php scripts/doctor.php
php -S localhost:8000 -t public
bash
php scripts/install-config.php .
php scripts/doctor.php
sh
curl -u admin:secret "http://localhost:8000/index.php?action=tables"
curl -H "X-API-Key: YOUR_KEY" \
"http://localhost:8000/index.php?action=list&table=users"
curl -X POST -d "username=admin&password=secret" \
"http://localhost:8000/index.php?action=login"
curl -H "Authorization: Bearer <token>" \
"http://localhost:8000/index.php?action=list&table=users"
# Delete dex.php?action=bulk_delete&table=users"
bash
curl "http://localhost:8000/index.php?action=openapi"
bash
composer install
./vendor/bin/phpunit
./vendor/bin/phpstan analyse
php scripts/doctor.php