Laravel API Route Not Found

11,565

Solution 1

try php artisan route:clear may work for you

Solution 2

Run sudo a2enmod rewrite to enable the mod_rewrite on the .htaccess file, then sudo service apache2 restart

Solution 3

check routing middleware https://laravel.com/docs/8.x/routing#route-groups?

Route::middleware('api')->group(function () {

    Route::get('testroute', [TestController::class, 'index']); 
}

URL:

http://127.0.0.1:8000/api/testroute
Share:
11,565
danielrvt
Author by

danielrvt

Computer Engineer graduated from Universidad Simon Bolivar, currently living in Caracas, Venezuela. GIS, Mobile and Web app developer... Web is my favorite. Always thinking about user experience and passionate about Python and JavaScript (There is something sexy about dynamic languages...). I also love using GIT and developing Augmented Reality applications with ARToolkit. My account on GitHub is this: https://github.com/danielrvt. See you on SO!!!

Updated on June 08, 2022

Comments

  • danielrvt
    danielrvt almost 2 years

    I'm trying to test an API route, but I always get 404 Not Found.

    I'm using this command:

    curl http://localhost:8000/api/veip
    

    This is my routes/api.php

    <?php
    
    use Illuminate\Http\Request;
    
    Route::get('/veip', function () {
        return 'Hello World';
    });
    

    And this is my php artisan route:list output:

    +--------+----------+----------+------+---------+------------+
    | Domain | Method   | URI      | Name | Action  | Middleware |
    +--------+----------+----------+------+---------+------------+
    |        | GET|HEAD | /        |      | Closure | web        |
    |        | GET|HEAD | api/veip |      | Closure | api        |
    +--------+----------+----------+------+---------+------------+
    

    So the route does exists

    I don't know what's going on here...