Api: Routes not being registered

Created on 22 Jul 2015  Â·  22Comments  Â·  Source: dingo/api

Hello,

Just installed a fresh Laravel 5.1 application, proceeded to pull in this package and all is well.

{
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "dingo/api": "0.10.*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

_Obviously, removed the other irrelevant stuff to show I have this set up correctly._

Registered the service provider in config/app.php for Laravel

Dingo\Api\Provider\LaravelServiceProvider::class

Published the config file, again for Laravel (config/app.php)

php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"

Now, for the routes (app\Http\routes.php)

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', ['namespace' => 'InkedFemales\Http\Controllers'], function ($api) {

    $api->resource('photos', 'PhotosController');

});

As far as I'm aware, this is correct. If my namespacing was incorrect, I know it throws a ReflectionException when running php artisan - which I also tested by misspelling controller and it did exactly that (throwing the exception).

But this is my problem, when running php artisan api:routes I just get

Your application doesn't have any routes.

Why is this? Am I missing something?

Really appreciate what you have done with this package so far!

Most helpful comment

@punit006 see #1165

Someone has submitted a PR for a fix. #1152

All 22 comments

In addition to this, of course I thought it would be worth noting I have the API_PREFIX value added to my .env file.

API_PREFIX=api

So I'm currently hitting the http://inkedfemales.dev/api/photos route to see the output (404'ing right now)

That command will not show registered API routes. There is an api:routes
command although it's broken at the moment.

As for not seeing anything when you are in the browser, have you tried just
a regular $api-get?

Also you don't have to use the env file. If you've published the config you
can set the prefix there.

On Thu, 23 Jul 2015 07:33 Joe Dawson [email protected] wrote:

In addition to this, of course I thought it would be worth noting I have
the API_PREFIX value added to my .env file.

API_PREFIX=api

So I'm currently hitting the http://inkedfemales.dev/api/photos route to
see the output (404'ing right now)

—
Reply to this email directly or view it on GitHub
https://github.com/dingo/api/issues/533#issuecomment-123873296.

Hey!

I kept running php artisan route:list out of habit, sorry buddy.

I have indeed, I just set up a route:

$api->get('test', function() {
    return ['foo' => 'bar'];
});

When I then hit http://inkedfemales.dev/api/test I still get a 404 - any ideas?

Hm, it all looks good to me and should be working. Must be something
missing though and it's probably something small and obvious.

What kind of 404? A Laravel 404?

On Thu, 23 Jul 2015 07:45 Joe Dawson [email protected] wrote:

Hey!

I kept running php artisan route:list out of habit, sorry buddy.

I have indeed, I just set up a route:

$api->get('test', function() { return ['foo' => 'bar'];});

When I then hit http://inkedfemales.dev/api/test I still get a 404 - any
ideas?

—
Reply to this email directly or view it on GitHub
https://github.com/dingo/api/issues/533#issuecomment-123876077.

Looks like the usual 404 response.

screen shot 2015-07-23 at 10 14 48

Could it be that my vendor is _empty_ in my config/api.php? I'm at work all day so can't check until this evening.

Had another peep at the documentation, is this a typo? https://github.com/dingo/api/wiki/Configuration

Vendor

Your vendor name is typically a short name of your application, all lowercase.

You can configure this in your .env file.

API_PREFIX=app

Should this be API_VENDOR?

Double check your configuration. If you enable API_DOMAIN then that domain should be also registered in you http server configuration and available through dns or hosts file.

You can't use both API_DOMAIN and API_PREFIX.

@lightvision I'm just using API_PREFIX

try something like this:

$api->version('v1', function($api) {
            $api->group(['namespace' => $this->namespace], function($api) {
                require app_path('Api/v1/Http/admin_routes.php');
            });
            # other routes here ...
        });

of course the code above assumes that you are using a namespace too.

I am a little bit busy now, but double check your configguration and your api route definition. Everything should be working.

Yeah that documentation is a typo.

I'm not going to be able to look at this properly for a few days as I'm on
the road.

Try another fresh install with the absolute bare minimum.

On Thu, 23 Jul 2015 19:36 Marius Ionel [email protected] wrote:

try something like this:

$api->version('v1', function($api) {
$api->group(['namespace' => $this->namespace], function($api) {
require app_path('Api/v1/Http/admin_routes.php');
});
# other routes here ...
});

of course the code above assumes that you are using a namespace too.

I am a little bit busy now, but double check your configguration and your
api route definition. Everything should be working.

—
Reply to this email directly or view it on GitHub
https://github.com/dingo/api/issues/533#issuecomment-124034003.

No worries, I won't be able to look at it until this evening so will update when I get a chance. Appreciate the help so far!

Guys, please ignore this lol. My vagrant machine hadn't been provisioned.

D'oh!

On Fri, 24 Jul 2015 03:23 Joe Dawson [email protected] wrote:

Guys, please ignore this lol. My vagrant machine hadn't been provisioned.

—
Reply to this email directly or view it on GitHub
https://github.com/dingo/api/issues/533#issuecomment-124172899.

@lightvision , I am trying to migrate API's form site to MAMP. When I run php artisan api:routes show all routes, but when I am try on browser NotFoundHttpException in /Applications/MAMP/htdocs/api-laravel/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php line 161:
Please Guide me How I can resolve this issue.

I am facing the same issue. Please help !
issue

@punit006 how're you registering your route(s)?

@JoeDawson Hello Joe. This is my route defination -

$api = app('Dingo\Api\Routing\Router');

Route::get('/', function () {
    return view('welcome');
});

$api->version('v1', function ($api) {
    $api->get('test', function () {
        return 'It is ok';
    });
});

qwe

@punit006 That does seem odd, not sure that's something I can help with as my original issue was related to my Homestead server not being correctly configured. (Looks like you're just using php artisan serve)

Hope you can solve it with someones help :)

@punit006 Do you have an API_PREFIX or API_DOMAIN setup in your .env file?

Hi @hskrasek thanks ! my problem has been solved. Actually i was using API_PREFIX as well as API_DOMAIN. I solved the problem by setting API_DOMAIN value to null. Now i am getting the response but still there seems some problem. My api response -

`[{
"id":1
,"p_name":"Dell",
"p_type":"Laptop",
"p_desc":"ABC",
"p_img":"",
"p_price":"50000"
}]

{
"message":"Method gatherRouteMiddlewares does not exist.",
"status_code":500
}`

Can you share your composer.json?

error with gatherRouteMiddlewares has something with laravel 5.3 or a package that expects laravel 5.3 (like an old packager of cors)

Sure @catalinux , here is my composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "minimum-stability": "stable",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*",
        "dingo/api": "1.0.*@dev"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.0",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

@punit006 see #1165

Someone has submitted a PR for a fix. #1152

Was this page helpful?
0 / 5 - 0 ratings