API Keys

  1. Rate Limiting
  2. JWT Authentication
  3. Idempotency
  4. API Keys
  5. API Versioning
  6. Pagination
  7. Consistent Error Format
Client
Server

Before

Route::get('/api/v1/reports', [ReportController::class, 'index']);

// any caller can hit this — no way to tell who,
// and no way to shut just one client off

After

Route::middleware('auth.apikey')
    ->get('/api/v1/reports', [ReportController::class, 'index']);

class AuthenticateApiKey
{
    public function handle(Request $request, Closure $next): mixed
    {
        $client = ApiClient::whereKey($request->header('X-Api-Key'))
            ->firstOrFail();

        return $next($request);
    }
}
{CC}