Service module example: Echo service

This service can be useful as an example, and as a test to make sure the services are functioning. This module simply replies with the message it is sent.

<?php
/**
* Implementation of hook_help().
*/
function echo_service_help($section) {
  switch (
$section) {
    case
'admin/help#services_node':
      return
t('<p>Provides echo methods to services applications. Requires services.module.</p>');
    case
'admin/modules#description':
      return
t('Provides echo methods to services applications. Requires services.module.');
  }
}

/**
* Implementation of hook_service()
*/
function echo_service_service() {
  return array(
   
// echo.echo
   
array(
     
'#method'   => 'echo.echo',
     
'#callback' => 'echo_service_echo',
     
//'#auth'     => false,
     
'#return'   => 'struct',
     
'#args'     => array(
        array(
         
'#name'         => 'message',
         
'#type'         => 'string',
         
'#description'  => t('The message to return.'),
        )),
     
'#help'     => t('Returns an object containing a sessid and user.'))
     
  );
}

function
echo_service_echo($message) {
 
 
$return = new stdClass();
 
$return->sessid = session_id();
 
$return->message = $message;
 
  return
$return;
}
?>

To install, in your modules directory make a directory named echo_service and install the above file as echo_service.module. Then put the following in that directory as echo_service.info. Then go to your Administration >> Modules and enable the Echo Service that shows up.

; $Id$
name = Echo Service
description = Provides echo services, such as if you want a ping ability to make sure the service is alive.
package = Services - services
dependencies = services
project = "services"

 
 

Drupal is a registered trademark of Dries Buytaert.