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

brakkar's avatar

Laravel and REST ?

Hi, I plan to use laravel to build an html website.

At a later date, I plan to extend it to be consumed by mobile iOS app. So the user will need to perform CRUD operations, and authenticate from the mobile app through REST.

Can the same initial Laravel project install be extended to serve the REST data to the mobile clients? Briefly, how would it be structured, so regular HTTP responses coexist with REST stuff inside the same laravel install?

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

Both can co-exist in the same project. There is a routes/web.php file for Session-based Request/Response cycle, and a routes/api.php file for non-Session API Request/Responses. The latter creates URLs with a api/ prefix (by default).

Beyond that, there are a number of approaches you can take for structuring your application code depending on preference and/or size. The very simplest approach would reuse the same Controller actions for both web and API requests, branching inside the Controller action depending on the Request source, e.g:

if ($request->expectsJson()) {
	return response()->json([/* payload */]);
}

return view('name-of-view', [' /* view data */]);

This will probably get tedious after a bit... If you wish to structure your application so that logic is available to both web and API clients, then you can consider Actions (like Jetstream does) - you will have separate web and API Controllers which will delegate to common Actions.

1 like

Please or to participate in this conversation.