Service module example: Echo service

Last updated on
30 April 2025

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.


/**
 * 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 Administer > Site building > 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"

For Drupal 6.X

;$Id$
name = "Echo Service"
description = "Provides echo services, such as if you want a ping ability to make sure the service is alive."
core = 6.x
dependencies[] = services

Help improve this page

Page status: Not set

You can: