Search code examples
phpresthttp-status-code-404restler

Restler php returning 404 for all results


I've been looking into implementing a REST implementation for my API and came across Restler. I've installed Restler 2.0 and am using Apache and php > 5.3. My class is below:

Class Sample 
{
   function gettest()
   {
      return "This is a test";
   }
}

and the index.php is:

set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/restler/');
require_once('path/to/Sample.class.php');
spl_autoload_register('spl_autoload');
$r = new Restler();
$r->setSupportedFormats('JsonFormat');
$r->addAPIClass('Sample');
$r->handle();

and instead of using an .htaccess, I've included the following inside a

<Directory /path/to/REST_DIR>
    AllowOverride All
    Options +FollowSymLinks     
    DirectoryIndex index.php

RewriteEngine On
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
Order deny,allow
    Allow from all

</Directory>

in my httpd.conf file (since it is supposed to be faster if you have access to edit it).

Whenever I try the following path:

http://www.myhost.com/REST_DIR/test/

I get:

{
  "error": {
    "code": 404,
    "message": "Not Found"
  }
}

Is there something I'm missing or some way to more thoroughly debug Restler to determine why it can't find the function gettest()?

Thanks in advance.

R


Solution

  • as per the current configuration you can expect result from http://www.myhost.com/REST_DIR/sample/test

    If you want the url to be http://www.myhost.com/REST_DIR/test instead, change index.php as follows

    set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/restler/');
    require_once('path/to/Sample.class.php');
    spl_autoload_register('spl_autoload');
    $r = new Restler();
    $r->setSupportedFormats('JsonFormat'); //not needed JSON is the default
    $r->addAPIClass('Sample',''); // note the empty string
    $r->handle();