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

Custom url segment breaks manual route to root #470

Open john-webb opened 9 years ago

john-webb commented 9 years ago

I would like to add my api class and map it to the empty string like so.

$r->addAPIClass('Group', '');

However when I do this my manual routing breaks in the class

/**
* Manually routed method.
*
* @url GET /
* @return array
*/
 protected function all() {
      return $this->db->formatSelect($this->db->all($_GET['uid']));
}

This is because Restler now thinks that my authentication query string is a parameter to this method. If I add

@url GET /{id}

and then call

GET http://localhost/api/group/?uid=459&ukey=....

$id comes through as the query string. I can fix this by added a double forward slash // after group but I would like not to.

Arul- commented 9 years ago

I'm a bit confused with your examples id in your routing is the same as uid you are getting?

Please help me understand the situation better

john-webb commented 9 years ago

Sorry for the confusing. So when I call

GET http://localhost/api/group/?uid=459&ukey=772f6ee7135efacd55f5

I expect the first case of the manual routing to be matched * @url GET / but instead the second case is matched and $id becomes the whole query string

   /**
     *
     * @url GET /
     * @url GET /{id}
     * @return array
     */
    protected function all($id = NULL) {
        var_dump($id); //uid=459&ukey=772f6ee7135efacd55f5
        return $this->db->formatSelect($this->db->all($_GET['uid']));
    }