If the said API path is gonna be used by my application only, I wouldn't with bother creating additional API routes. But if you're exposing this resource to other services/apps, I think it is better to keep it in the api.php file.
Dec 2, 2018
2
Level 8
Is it OK to have duplicate routes for Web and API?
I have a resource controller that has a show() method and uses route model binding. The method looks like this:
public function show(Resource $resource)
{
if (request()->wantsJson()) {
return $resource;
}
return view('dashboard.resource', compact('resource'));
}
Is it acceptable to have the route to get this resource in both my routes/web.php and routes/api.php? By keeping it only in my routes\web.php file, it feels wrong when calling it from my API and by keeping it only in my routes\api.php file, it feels wrong appending /api/ to the URL.
Please or to participate in this conversation.