Access the Laravel API route 5.7

Asked

Viewed 243 times

1

I’m learning to use Laravel as a Rest API and went to test by Postman a route that returns a string, but I can’t find an error. Returns not found.

Address: http://127.0.0.1:8000/api/dot/

<?php

use Illuminate\Http\Request;


Route::group(['prefix' => 'api'], function()
{
    Route::group(['prefix' => 'ponto'], function()
    {
        Route::get('/', function()
        {
            return 'Teste';
        });
    });
});

Resolution: I just didn’t know it was standard to put /api to Rest.

  • Hello, Remove the group that is within the group and in get put: "point" in place of / I hope to have helped

  • Where did you set this route?

1 answer

1


The solution is simple. Try this: http://127.0.0.1:8000/api/api/dot/

But that question comes, why is that? The answer is also simple: If you look at the Provider that records the routes: Routeserviceprovider, in the mapApiRoutes method, you will notice that there is already a prefix called api, for routes that are in the api.php file, so it is not necessary to set an api prefix again in your route file.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.