Luracast / Restler

Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and/or RESTful API
http://luracast.com/products/restler/
GNU Lesser General Public License v2.1
1.36k stars 315 forks source link

Question about routing #647

Closed ci-90 closed 3 years ago

ci-90 commented 3 years ago

If i access https://api.xxxxx.com/say/hello I get the following error:

{ "error": { "code": 404, "message": "Not Found" }, "debug": { "source": "Routes.php:380 at route stage", "stages": { "success": [ "get" ], "failure": [ "route", "negotiate", "message" ] } } }

My httaccess contains

RewriteEngine On RewriteCond %{HTTP_HOST} ^api. RewriteRule ^$ /api/index.php [QSA,L] RewriteCond %{HTTP_HOST} ^api. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /api/index.php [QSA,L]

index.php contains

require_once './vendor/autoload.php'; use Luracast\Restler\Restler; $r = new Restler(); $r->addAPIClass('say'); // repeat for more $r->handle();

say.php contains

class say { function hello($to='world') { return "Hello $to!"; } function hi($to) { return "Hi $to!"; } }

My index.php with the restler code is in the directory /var/www/html/api

Any idea what might be the issue? Please tell me if you need more information.

Arul- commented 3 years ago

can you try https://api.xxxxx.com/say/hello/something

ci-90 commented 3 years ago

Thank you for your quick response. Unfortunately it leads to the same error.

gironeremi commented 3 years ago

Hi there! Unfortunatelly, I've the same issue :/ Impossible to make the 1st example -___-,

Arul- commented 3 years ago

can you try https://api.xxxxx.com/say/hello?to=something

gironeremi commented 3 years ago

Didn't work. Apparently, there is a problem with some routes.php. error_1

I've correctly installed with last version code, installed dependencies with 'composer install', etc.

BUT, good thing, at the end of the result, we can see my JSON result!

gironeremi commented 3 years ago

error_2

Arul- commented 3 years ago

A deprecation warning is fine! just turn it off on php.ini or by adding

error_reporting(E_ERROR | E_PARSE);

to your index.php

gironeremi commented 3 years ago

Success! It worked! I've tried with one of my Classes, it works perfectly. Thank you so much! It will be very useful in my future work.

api_rest_success

Arul- commented 3 years ago

Hope the suggested solution works for @ci-90 as well! I will close the issue for now! Let us know if you still need help!