Installation
Install via Composer
composer require bluebeetlept/api-toolkit
Publish Configuration
php artisan vendor:publish --tag=api-toolkit-config
This creates config/api-toolkit.php with the following defaults:
return [
'pagination' => [
'default_size' => 20,
'max_size' => 100,
'valid_sizes' => [10, 20, 40, 80, 100],
],
'exceptions' => [
'dont_report' => [],
'domain' => [],
],
'openapi' => [
'title' => env('APP_NAME', 'API'),
'version' => '1.0.0',
'description' => '',
'servers' => [
['url' => env('APP_URL', 'http://localhost') . '/api'],
],
],
];
Exception Handler
To render all exceptions as JSON:API errors, register the handler in your bootstrap/app.php:
use BlueBeetle\ApiToolkit\Exceptions\ConfigureExceptionHandler;
->withExceptions(new ConfigureExceptionHandler())
Middleware
Add the JSON:API content type middleware to your API routes:
use BlueBeetle\ApiToolkit\Http\Middleware\ForceJsonApiResponse;
Route::middleware([ForceJsonApiResponse::class])->group(function () {
// Your API routes
});
Optionally, add language detection:
use BlueBeetle\ApiToolkit\Http\Middleware\DetectLanguage;
Route::middleware([DetectLanguage::class])->group(function () {
// Routes with locale detection from Language header
});