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.

Reply to

Use Markdown with GitHub-flavored code blocks.