Just getting started with Services, finding some issues...

Events happening in the community are now at Drupal community events on www.drupal.org.
bsenftner's picture

Using Drupal 6.13, Services 6x-2x-dev

I am working towards implementing a web API to expose some computational services of my company. Starting out with a basic module that depends upon the Services.module, I am seeing these unexpected behaviors:

  • only the first service function appears, none of the others
  • the '#help' text for my service never appears
  • if I deactivate my module, I still see it listed in the Services Browser (admin/build/services)

Here's the code that I have, which is pretty little at this point. I really only care about the first issue at this point (I'll figure out the rest as I continue development)
What am I doing wrong such that only the first function is ever recognized?

function myAPI_service()
{
  return array(
     array(
        '#method'   => 'myAPI.init',
        '#callback' => 'myAPI_init',
        '#return'   => 'string',
        '#help'     => t('Initialize, or verify initialization, of the myAPI subsystem'),   // where are you??? never appears!
     ),
     // behaves as if the below array does not exist
     array(
        '#method'   => 'myAPI.test',
        '#callback' => 'myAPI_test',
        '#return'   => 'string',
        '#help'     => t('test routine for understanding how the Services module works'),
     ),
  );
}

// this one works fine:
function myAPI_init()
{
  return 'okay';
}

// never called, due to something missing in myAPI_service() array return value above?
function myAPI_test()
{
  return 'test returns okay';
}

Comments

answering my own question

bsenftner's picture

after examining some of the other example services within services.module, I noticed the usage of hook_disable() and hook_enable(), and added them to my module:

function myAPI_disable() {
  cache_clear_all('services:methods', 'cache');
}
function myAPI_enable() {
  cache_clear_all('services:methods', 'cache');
}

Once these were in place, all the above issues disappeared. Somewhere there ought to be a note within the Services documentation pointing out how important it is to use these hooks.

This is now mentioned in the

wmostrey's picture

This is now mentioned in the documentation: http://drupal.org/node/118126

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: