ken
ken

Reputation: 9013

API Explorer not using URL parameters

I have created a RESTful API that has an optional parameter passed in as a URL variable. It seems to work correctly when executing from the browser directly but when trying it in the API Explorer it lists the parameter but ignores it when executing it. I have no idea where to start to look in solving this. Any help would be greatly appreciated.

The class definition is as follows:

class actions {

  /**
   * LIST available Actions
   *
   * List all the actions that a user (or app) can choose from. The response list  
   * will include [name],[slug/id], and [description] attributes. If you want a more complete set of 
   * meta attributes for the actions then you can specify "meta=all" in the request url. For full spec of
   * response please review LG_actions_list.json.
   *
   * @url GET /available
   *
   * @param $meta {@from url} Optional parameter to control the amount of meta-data passed back. Values are "none","normal", and "all"
   **/
  public function available ($meta="normal")
  {
    return "list actions (meta level set to $meta)";
  }

}

In this case I can type "all" as the value of $meta in the API explorer but the response is still "list actions (meta level set to normal)".

UPDATE:

In order to clarify this behaviour I am adding the API Explorers output and the output I get when I call the service directly:

enter image description here

In comparison, when actually using the API I get the correct results. Typing this into Chrome:

http://[domain]/api/actions/available?meta=foobar

I get the desired output of:

"list actions (meta level set to foobar)"

Upvotes: 2

Views: 416

Answers (1)

Arul Kumaran
Arul Kumaran

Reputation: 993

There are few problems with what you are doing with the above code

  • Optional Parameters are better left to query string
  • When you add a manual route using @url no auto routes will be added for that method

Do the following to make it work.

  • Changed the method name to get to map it to root of the class
  • Turned off smart auto routing

Now in the explorer there will be two operations listed

  • actions.json
  • actions.json/{meta}

.

class actions {

     /**
     * LIST available Actions
     *
     * List all the actions that a user (or app) can choose from. The response list
     * will include [name],[slug/id], and [description] attributes. If you want a more complete set of
     * meta attributes for the actions then you can specify "meta=all" in the request url. For full spec of
     * response please review LG_actions_list.json.
     *
     * @smart-auto-routing false
     * @param $meta Optional parameter to control the amount of meta-data passed back. Values are "none","normal", and "all"
     **/
    public function get ($meta="normal")
    {
        return "list actions (meta level set to $meta)";
    }

}

Upvotes: 2

Related Questions