How do I define an API route?

Posted 1 year ago by malhayek

I never used Laravel to create API that return JSON. This time I have an application that need web routes and some API routes.

For my API route, I added the following route to my /routes/api.php file

Route::get('getinfo/{id}', '[email protected]')
    ->where('id', '[0-9]+');

However, when I go to / I get redirected to /home url.

What else that is different that I have to do to get the api routes to work?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.