0PricingLogin
PHP Academy · Lesson

API Routes and Resource Controllers

Register RESTful routes and generate resource controllers with Artisan.

API Routes in Laravel

Define API routes in routes/api.php. These routes are automatically prefixed with /api and use the api middleware group (stateless — no session/cookies).

Basic API Route

Return JSON from a closure.

<?php
Route::get("/users/{id}", function (int $id) {
    $user = User::findOrFail($id);
    return response()->json($user);
});

All lessons in this course

  1. API Routes and Resource Controllers
  2. API Resources and JSON Responses
  3. Authentication with Laravel Sanctum
  4. Rate Limiting and API Versioning
← Back to PHP Academy