Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stormy478's avatar

API

Hi. This might seem like a silly question but I would like to confirm if APIs are laravel routes.

0 likes
5 replies
CamKem's avatar

Can you clarify what you are asking a bit further? The term API in the context of Laravel refers to a REST program interface & not a web interface. However essentially any collection of programatic syntax that you create to handle some type of functional connectivity could be considered a API, so technically you could say that even the web routes are an API.

To understand what you are trying to workout, can you elaborate further?

stormy478's avatar

@CamKem So for example I'm asked can you give me an API for getUsers(). In my mind I'm thinking that means a route Route::get('/users', [ UserController::class, 'getUsers') and then maybe a UserController with that function. But I'm not 100% sure if what I'm thinking is correct.

CamKem's avatar

@stormy478 I would try and stick to a RESTful naming conventions of your method, if getUsers() is to display a list of the users, then generally this would use a method name of index().

So for a web route & controller method it would be like this:

//route
Route::get(‘/users’, [UserController::class ‘index’])
->name(‘users.index’);

//controller method
index()
{
    return view(‘users.index’, [
        ‘users’ => User::all()
    ]);
}
stormy478's avatar

@CamKem ok cool, I will do that, but is my understanding of APIs for laravel right?

CamKem's avatar
CamKem
Best Answer
Level 10

@stormy478 Yes, you seem to be on the right path. In the context you are talking: API - is a RESTful resource, for getting, posting, updating & destroying data, so other programs can obtain access to your data.

I would do a little bit more learning on the difference between API routes & web routes. This article should help you have a better understanding

If you are happy with the answer, can you please mark Best Answer to close the thread?

EDIT: also a good discussion on it here: https://www.reddit.com/r/laravel/comments/852lls/web_routes_vs_api_routes/

Please or to participate in this conversation.