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
- API Routes and Resource Controllers
- API Resources and JSON Responses
- Authentication with Laravel Sanctum
- Rate Limiting and API Versioning