tarikulwebx/laravel-api-starter
Laravel 12 API-only starter with Sanctum auth, email verification, password reset, and Scramble OpenAPI docs
Laravel API Starter
A Laravel 12 API-only starter kit with Laravel Sanctum authentication, rate limiting, CORS, and OpenAPI documentation via Scramble.
Features
- API-only — No frontend; designed for SPA or mobile clients
- Sanctum authentication — Token-based auth with register, login, logout
- Email verification — Optional verification flow with resend
- Password reset — Forgot and reset password via token
- Rate limiting — Throttling for auth, API, and authenticated endpoints
- CORS — Configurable via
APP_FRONTEND_URL/CORS_ALLOWED_ORIGINS - OpenAPI docs — Scramble generates docs from routes and Form Requests
Requirements
- PHP 8.2+
- Composer
- SQLite (default) or MySQL/PostgreSQL
Installation
# Clone and enter the project
git clone <repository-url> laravel-api-starter
cd laravel-api-starter
# One-time setup (install, .env, key, migrate)
composer run setupOr step by step:
composer install
cp .env.example .env
php artisan key:generate
php artisan migrateConfiguration
.env— Copy from.env.example. SetAPP_URLand, for CORS,APP_FRONTEND_URLorCORS_ALLOWED_ORIGINS(comma-separated).- Database — Default is SQLite; configure
DB_*for MySQL/PostgreSQL if needed. - Mail — Set
MAIL_*for email verification and password reset (e.g. Mailtrap, SMTP).
Running the Application
The app is intended to be served by Laravel Herd at https://laravel-api-starter.test (or your project’s kebab-case name). No php artisan serve is required when using Herd.
For local development without Herd:
php artisan serveOptional (if using queues):
composer run dev # runs serve + queue:listenAPI Documentation
Scramble serves interactive API docs at /docs/api when the app is running. It builds OpenAPI from your routes and Form Request validation.
API Endpoints
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /register |
— | Register; returns user + token; sends verification email |
| POST | /login |
— | Login; returns user + token |
| POST | /logout |
Bearer | Revoke current token |
| GET | /user |
Bearer | Current authenticated user |
| POST | /email/verify/{id}/{hash} |
Bearer + Signed | Verify email |
| POST | /email/send-verification |
Bearer | Resend verification email |
| POST | /forgot-password |
— | Request password reset email |
| POST | /reset-password |
— | Reset password with token |
Authenticated requests must send: Authorization: Bearer <token>.
Testing
Tests use Pest. Run:
php artisan test --compactOr via Composer:
composer run testCode Style
Laravel Pint is used for formatting:
vendor/bin/pint --dirty --format agentLicense
The Laravel framework is open-sourced under the MIT license.