Overview Most Laravel starters focus on full-stack experiences, bundling Blade or Vite. However, modern backends often serve as headless engines for mobile apps or SPAs. The Laravel API Starter Kit by Jean Mark fills this void. It provides a lean, opinionated foundation that strips away the frontend fluff, focusing entirely on robust API architecture, versioning, and automated documentation. Prerequisites To effectively use this kit, you should be comfortable with: * **PHP 8.2+** and Laravel fundamentals. * **RESTful Principles**: Understanding HTTP methods and status codes. * **Composer**: Managing PHP dependencies. * **Docker or Local Servers**: Familiarity with Laravel Herd or Sail for environment hosting. Key Libraries & Tools * Laravel 12: The underlying framework providing the core engine. * Doo Scramble: An automated Open API 3.1 documentation generator. * Laravel API Route: A package for managing multi-strategy versioning (URL, Header, etc.). * Spatie Query Builder: Simplifies filtering, sorting, and including relations via URL parameters. * Laravel Sanctum: Handles lightweight API token authentication. Code Walkthrough 1. Installation and Setup Clone the repository and run the standard Laravel initialization commands. This kit skips the traditional `npm install` because it contains no frontend assets. ```bash git clone https://github.com/Grazulex/laravel-api-kit api cd api composer install php artisan key:generate php artisan migrate ``` 2. Versioning and Routes Routes are not defined in the standard `api.php`. Instead, they reside in version-specific files, managed by the Laravel API Route package. Configuration happens in `config/api-route.php`. ```php // routes/api/v1.php Route::post('/login', [AuthController::class, 'login'])->name('login'); ``` 3. The API Controller Pattern The kit uses an abstract `APIController` that utilizes an `ApiResponse` trait. This ensures consistent JSON structures across your entire application. ```php // app/Http/Controllers/Api/AuthController.php public function register(RegisterRequest $request) { // Logic here... return $this->created($user_resource); } ``` Syntax Notes The kit utilizes **Traits** to inject standardized response methods like `success()`, `created()`, and `unauthorized()` into controllers. This promotes DRY (Don't Repeat Yourself) principles. It also leverages **Eloquent API Resources** to transform model data before it leaves the server, ensuring the internal database schema isn't leaked directly to the client. Practical Examples This starter is ideal for building **Mobile App Backends** where you need quick iteration on endpoints without managing a frontend. It is also perfect for **Microservices** that require standardized documentation through Doo Scramble, allowing other teams to integrate with your service by simply visiting the `/docs` endpoint. Tips & Gotchas * **Abstract vs. Trait**: While the kit uses an abstract base controller, you can apply the `ApiResponse` trait directly to specific classes if you prefer composition over inheritance. * **Unused Packages**: Spatie packages like `laravel-data` are included in `composer.json` but aren't strictly required. They serve as architectural suggestions for handling DTOs.
Steve
People
- Jan 20, 2026
- May 28, 2025
- Feb 25, 2025
- Jan 9, 2025
- Jan 7, 2025
Overview Laravel 10.42 continues to refine the developer experience by removing friction from common tasks. This release focuses on reducing boilerplate in HTTP requests, enhancing queue observability, and simplifying how we handle string data and on-demand notifications. These updates prioritize clean code and centralized configuration. Prerequisites To follow this guide, you should be comfortable with PHP 8.x and Laravel fundamentals. Specifically, you should understand how Service Providers function and have experience with the HTTP Client and Queue systems. Key Libraries & Tools * **Laravel Framework**: The core PHP framework receiving these updates. * **Guzzle**: The underlying library for Laravel's HTTP client. * **Tinkerwell**: A code runner used for testing string helpers. Centralizing HTTP Client Settings Configuring timeouts and base URLs across multiple commands often leads to repetitive code. Laravel now allows you to set global defaults in your `AppServiceProvider` using the `globalOptions` method. ```python // AppServiceProvider.php use Illuminate\Support\Facades\Http; public function boot(): void { Http::globalOptions([ 'timeout' => 5, 'connect_timeout' => 2, 'base_uri' => config('services.api.url'), ]); } ``` Once defined, every call to `Http::get()` or `Http::post()` throughout your application automatically inherits these settings. This ensures consistency and makes updating external API configurations a single-point operation. Advanced String Manipulation with Unwrap While `Str::wrap()` has long been available to surround text with characters, the new `unwrap` method provides the logical inverse. This is particularly useful when processing raw input or CSV data where values are encased in quotes. ```python use Illuminate\Support\Str; // Returns "Laravel" $unwrapped = Str::unwrap("'Laravel'", "'"); ``` Fluent On-Demand Notifications Previously, routing on-demand notifications to multiple channels required chaining the `route` method repeatedly. The new `routes` method accepts an associative array, making the syntax significantly cleaner when hitting multiple endpoints like Slack, Mail, and SMS simultaneously. Syntax Notes * **Array Mapping**: The `routes` method uses an associative array where keys represent the channel and values represent the destination. * **JobQueuing vs JobQueued**: The new `JobQueuing` event fires *before* the job hits the provider, allowing you to calculate the latency of the queuing process itself. Tips & Gotchas When using global HTTP options, remember that local options passed directly to a request will override the globals. This is by design, allowing you to have a safe default while handling edge cases that require longer timeouts.
Jan 25, 2024