malhayek
137
11
Laravel

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]')
    ->name('some_name')
    ->where('id', '[0-9]+');

However, when I go to /myapp.dev/api/getinfo/1 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

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.