I have installed Restler on my local server to test and make some APIs for my project.
Api requests are handled via http://localhost/myproject/api/
.
The problem is that everytime i try to make a request i get the following error:
{
"error": {
"code": 404,
"message": "Not Found"
},
"debug": {
"source": "Routes.php:383 at route stage",
"stages": {
"success": [
"get"
],
"failure": [
"route",
"negotiate",
"message"
]
}
}
}
Also this is my .htaccess
:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api(.*)$ /myproject/api/api.php [QSA,L]
And this is what the api.php
looks like:
namespace myproject;
use Luracast\Restler\Restler;
require_once($_SERVER["DOCUMENT_ROOT"]."/myproject/resources/engine/settings.php");
require_once(Settings\Path\Absolute::$library."/restler/vendor/restler.php");
$restler = new Restler();
$restler->addAPIClass("myproject\\User");
$restler->handle();
I guess there's some misconfiguration around, but i really can't figure out what's wrong.
(I also tried some solutions on Stackoverflow but they doesn't seem to work for me)
Edit:
I tried reaching the example using the following path http://localhost/myproject/resources/engine/library/restler/public/examples
and they're working, so i guess it has to do with the configuration of Restler itself because it doesn't seem to work in http://localhost/myproject/api
.
Furthermore i also tried copying the Restler Explorer in http://localhost/myproject/api/explorer
and i keep receiving the error: 404 : Not Found ../resources.json
probably because i didn't install Restler in the root folder of my project. How am I supposed to install Restler in a different subfolder?
Edit 2: I just moved the following class into the example 001 folder:
class User {
function data() {
return "HELLO!";
}
}
and added this line inside the index.php
of the example:
$r->addAPIClass('User');
If i try to run the example at .../_001_helloworld/index.php/say/hello
it works without problems but if i try _001_helloworld/index.php/user/data
it isn't.
At this point i have lost every hope and i really need help 'cause really i'm missing something but really can't guess what :( HELP!
Here is how you can debug and find whats wrong,
Remove the namespace in api.php. It is not required and will cause issues.
Copy explorer folder to
/myproject/api
folder and add Resources class as an api classIf you are adding User class with a namespace, make sure it defined under that namespace and made available with your include statements or autoloader.
You can create
/myproject/api/cache
folder and make it writable. When you instantiate restler in production mode with cache refresh as shown below, it will create routes.php in cache folder which lists all the routes informationHope you find whats wrong with the above