How to use API Routes in Laravel 5.3
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Laravel is a widely used PHP framework that offers various features such as routing. One of its unique aspects is the division of routes based on their purpose – web and API routes. Laravel 5.3 provides dedicated files for these route types in order to facilitate better organization and management of your application's endpoints.
Understanding Web Routes
In general, you use the 'routes/web.php' file for defining web routes. These are standard HTTP requests handled through controllers and views. This file is where you usually put all your primary application routes. Here's an example of a basic route definition:php
Route::get('/', function() {
return "Welcome to my website!";
});Diving into API Routes
As mentioned at the start, Laravel 5.3 moved its API routes to a separate file named 'api.php.' This file is intended for handling all of your application's RESTful APIs and JSON responses. This type of route is meant to be accessed by applications instead of being displayed in a browser like web routes. To illustrate how this works, check out the following example:php
Route::get('/test', function() {
return "ok";
});http://localhost:8080/api/test
However, accessing the above URL through your browser (instead of an API client) will result in the error 'NotFoundHttpException' since web browsers don't understand JSON responses. Your requests should be made with a proper HTTP client like Postman or Curl to work correctly. This emphasizes that API routes are meant for APIs and not standard website traffic.