I wanted a simple and consistent way to create endpoints for pushing
and pulling data from the drupal using jquery (or anything that can
parse json). Right now it doesn't do any kind of message passing but
ideally you could hide the json messages and only expose associative
arrays.
What do you think about something like this:
/**
* Register endpoints example
* @return type
*/
function islandora_services_register_endpoints()
{
// Define the end points
return array(
'islandora_services' => array (
'myendpoint' => array (
'title' => 'test callback',
'function' => 'myendpoint_handler',
'param_count' => 1,
'example' => 'myendpoint/2345',
'security' => array('view')
),
'myendpoint2' => array (
'title' => 'test callback2',
'function' => 'myendpoint_handler2',
'param_count' => 2,
'example' => 'myendpoint/2345/235',
'security' => array('view')
),
)
);
}
/**
* Example callback
* @param type $param
*/
function islandora_services_myendpoint_handler($param) {
$results = "islandora_services_myendpoint_handler(".$param.");";
return $results;
}
/**
* Example callback
* @param type $param
*/
function islandora_services_myendpoint_handler2($param, $param2) {
$results = "islandora_services_myendpoint_handler(".$param.",".$param2.");";
return $results;
}
-Adam
Yeah, it uses the menu system to provide the callbacks with some
additional routing.
The main reasons are:
- It separates the menu hooks from the rest end points
- It keeps the endpoints organized in one area
- It can give you a list of all the registered end points to be displayed
- It routes messages for you including serializing the data
- It allows me to create tons of endpoints to be used both inside and
outside of drupal
You can have a look at it if you want.
https://github.com/bwoodhead/islandora_services
Ben
function islandora_services_menu() {
$items = array();
$items['islandora_services/rest'] = array(
'title' => $params['title'],
'page callback' => 'islandora_services_handler',
'access arguments' => $params['security'],
'type' => MENU_CALLBACK
);
$items['islandora_services/list'] = array(
'title' => 'Islandora Services List',
'page callback' => 'islandora_services_list_page',
'access arguments' => array('view'),
'type' => MENU_NORMAL_ITEM
);
return $items;
}
The next couple of parameters would get passed to the handler
function anyway.- It separates the menu hooks from the rest end points - It keeps the endpoints organized in one area
- It can give you a list of all the registered end points to be displayed
- It routes messages for you including serializing the data
- It allows me to create tons of endpoints to be used both inside and outside of drupal
Ben