Setting Up Laravel 11
Start with composer create-project laravel/laravel my-api. Laravel 11 has a minimal bootstrap structure compared to earlier versions, making it lighter out of the box.
Authentication with Sanctum
Laravel Sanctum provides a simple token-based authentication system perfect for SPAs and mobile apps. Run php artisan install:api to set it up automatically.
API Resources & Transformers
Use API Resources to transform your Eloquent models into consistent JSON responses. php artisan make:resource UserResource gives you full control over the output shape.
Validation with Form Requests
Keep your controllers clean by moving validation logic to Form Requests. php artisan make:request StoreUserRequest separates concerns beautifully.
API Versioning
Use route prefixes like /api/v1/ for versioning. Group related routes with Route::prefix('v1')->group() for clean organisation.
Rate Limiting
Laravel's built-in throttle middleware protects your API from abuse. Configure rate limits in your RouteServiceProvider or directly on routes with throttle:60,1.