Laravel Basic
Laravel Form
Laravel Database
Laravel Advance
Laravel makes it very easy to build REST APIs.
Unlike web routes, API routes are separated because APIs usually:
Laravel don't have api.php file. You should create in routes folder
<?php
use Illuminate\Support\Facades\Route;
Route::get('/hello', function () {
return response()->json(['message' => 'Hello from API!']);
});
This means:
you should register api.php file in bootstrap\app.php
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware): void {
})
->withExceptions(function (Exceptions $exceptions): void {
//
})->create();
Install postman Link
Run http://127.0.0.1:8000/api/hello in postman in prefix after url should come api