Question

First let me say that the new API Explorer in Restler is great. Very happy about its addition. Now, in typical fashion, let me complain about something that isn't working for me ...

The fact that Restler can return results in multiple formats is a very nice feature but I'm currently not using it (choosing to only use JSON as my return format). In the API Explorer I'd like all references to .json to not show up as this just complicates the look of the service architecture.

Here's a quick example:

class Users {
/**
* Preferences
*
* Preferences returns a dictionary of name-value pairs that provide input to applications that want to make user-specific decisions
* 
* @url GET /{user_id}/preferences
**/

function preferences ($user_id , $which = 'all') {
    return  "$which preferences for {$user_id}";
}

/**
* GET Sensors
*
* Get a list of all sensors associated with a user.
*
* @url GET /{user_id}/sensor 
**/
function sensor ($user_id) {
    return "sensor";
}

/**
* GET Sensors by Type
*
* @param $user_id The user who's sensors you are interested in
* @param $type The type of sensor you want listed. 
*
* @url GET /{user_id}/sensor/{type}
**/ 
function sensor_by_type ($user_id, $type) {
    return "specific sensor";
}


/**
* ADD a Sensor
*
* @param $user_id The user who you'll be adding the sensor to
*
* @url POST /sensor
**/ 
function postSensor() {
    return "post sensor";
}

}

In this example the API Explorer looks like this: enter image description here

The basic problem I'd like to remove is remove all ".json" references as the calling structure without the optional .json works perfectly fine.

Also, for those that DO want the .json showing up there's a secondary problem of WHERE does this post-item modifier show up? In the example above you have .json attaching to the "users" element in the GET's and to the "sensor" element in the PUT. This has nothing to do with the HTTP operation but rather it seems to choose the element which immediately precedes the first variable which may not be intuitive to the user and actually isn't a requirement in Restler (at least its my impression that you can attache .json anywhere in the chain and get the desired effect).

Was it helpful?

Solution

We are using safer defaults that will work for everyone, but made it completely configurable.

if you prefer .json to be added at the end, add the following to index.php (gateway)

use Luracast\Restler\Resources;
Resources::$placeFormatExtensionBeforeDynamicParts = false;

If you prefer not to add .json extension, add the following to index.php

use Luracast\Restler\Resources;
Resources::$useFormatAsExtension = false;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top