Search code examples
jsonrestlaravel-5laravel-5.3

Built api routes in laravel 5.x


I'm new in larevel. I want to create route in api.php. It's my code in this file

Route::middleware('auth:api')->get('/api', function (Request $request) {
    return response()->json([
        'name' => 'Abigail',
        'state' => 'CA'
    ]);
});

I need to return json but when I put url mysite.com/api/api and page redirect me to mysite.com/user. How I can avoid redirect I get correct url?


Solution

  • Remove auth middleware and try again like:

    Route::middleware('api')->get('/api', function (Request $request) {
        return response()->json([
            'name' => 'Abigail',
            'state' => 'CA'
        ]);
    });