Elgg has a set of functions and classes builtin to enable a plugin to expose functionality.
First, create a function which should be accessible via the API and which will handle data; for example function your_api_function(array $params). Next, you'll need to register that function with register_method(), which takes three parameters:
user.getEmail function your_api_function()) This registers the function api_name as the recipient of requests to the api.name API call, which takes two parameters: an integer and an optional string.
register_method("api.name", "api_name", array(
"param1" => array( // parameter name
'int' // The type (int,bool,string etc)
),
"param2" => array(
'string',
true // Optional parameter (default:false) specifying whether this parameter is optional.
)
));
We then define the api_name function:
function api_test($params) {
$int = $params[0];
if (isset($params[1])) $string = $params[1];
// Do some processing
return $arbitrary_result;
}
restapi, REST API, rest like api
Last updated 531 days ago by Pete Harris
