So far I've been building Laravel and Django apps that return views or templates from backend. So far so good.
However, I'm now building a Laravel API that gets called from a frontend AMP code.
In the old ways I do this in Laravel:
From web.php
Route::get('/', function () {
return view('welcome');
});
Or I can return the view from the controller.
However, if the Laravel app is an API that returns JSON, how can I design URLs?
Basically, if someone clicks a link on the homepage that should take hime to a user profile, say:
/user/{id}
Where will I decide how this URL looks like and which endpoint to call?
You can use the same route syntax, but instead of returning a view, you return a json response.
Take a look at the response documentation for all available types of responses.