3
This is the web service file _ws.php
<?php
/*
 Title: Hello World Example.
 Tagline: Let's say hello!.
 Description: Basic hello world example to get started with Restler 2.0.
 Example 1: GET say/hello returns "Hello world!".
 Example 2: GET say/hello/restler2.0 returns "Hello Restler2.0!".
 Example 3: GET say/hello?to=R.Arul%20Kumaran returns "Hello R.Arul Kumaran!".
 */
require_once '../restler/restler.php';
require_once 'news_class.php';
$r = new Restler();
$r->addAPIClass('news');
$r->handle();

This is the class file with the functions:

<?php
class news {
    function hello($to='world') {
        return "Hello $to!";
    }

    function listnews($page=0){
        $result = "";

        $xml_doc = new DOMDocument;
        $xml_doc->load('news.xml');

        $xsl_doc = new DOMDocument;
        $xsl_doc->load('news_list.xsl');

        $xsl_proc = new XSLTProcessor();
        $xsl_proc->importStyleSheet($xsl_doc);
        $xsl_proc->setParameter('', 'page', $page);
        $result = $xsl_proc->transformToXml($xml_doc);

        return $result;
    }


} // news -

If I named the listnews function to listNews, I get this error:

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

As long as the name is now mixed case, it works. Is it suppose to be like this? is there any way to use camel casing?

Thx!

472084
  • 17,666
  • 10
  • 63
  • 81
user642298
  • 41
  • 3

2 Answers2

0

Update for the answer by @richard_askew, he is right.

Class name, method name, and the parameter names have to be all lowercase when placed in the URL when we use auto routing in Restler version 2.1.5 or below

We have just released Restler version 2.1.6 which changes this behavior :)

Now class name, method name, and the parameter names specified in the url in any case (upper or lower or mixed) will matched with the correct method

Arul Kumaran
  • 983
  • 7
  • 23
0

Just to revisit this, I've been playing around with the code and I'm getting similar behaviour. The following naming conventions for my methods cause the 404 error:

mysite.com/myclass/testMethod
mysite.com/myclass/TestMethod

The following work as expected

mysite.com/myclass/testmethod
mysite.com/myclass/test_method

Any way (that I've missed or otherwise) to get Camel Case to work?

Update: The method name doesn't seem to be causing the error e.g. I can name it testMethod and still call it in lower case.

Richard Askew
  • 1,217
  • 1
  • 10
  • 16