drupal-7drupal-services

Can hit Drupal 7 REST resource endpoint but not with the CRUD operation added


I have a REST endpoint defined using the D7 services module. I have enabled the service and the CRUD operation. I have enabled the permission. When I hit the url for the endpoint, /myservice, I get a message

Services Endpoint "myservice" has been setup successfully.

When I hit /myservice/create (it's the Create CRUD service I have enabled), I just get a blank page, though the callback, below, has a print statement.

.module

function myservice_permission() {
    return array('create constructs' => array(
      'title' => t('create constructs'),
      'description' => t('Receive messages'),
    )
  );
}

function _myservice_access($ops, $args) {
  return TRUE;
}

function myservice_services_resources() {
  return array(
    'myservice_messages' => array(
        'create' => array(
        'help' => 'Creates messages',
        'callback' => '_myservice_create',
        'access callback' => '_myservice_access',
        'access arguments' => array('create constructs'),
        'access arguments append' => FALSE,
           'args' => array(
                array(
                    'name' => 'data',
                    'type' => 'struct',
                    'description' => '',
                    'source' => 'data',
                    'optional' => TRUE,
                ),          
           ),
        ),
    );
}
function _mymodule_create($data) {
  print '***here';
}

function myservice_services_endpoint() {
  $endpoints = array();
  $endpoint = new stdClass();
  $endpoint->disabled = FALSE;
  $endpoint->api_version = 3;
  $endpoint->name = 'myservice';
  $endpoint->server = 'rest_server';
  $endpoint->path = 'myservice_message';
  $endpoint->authentication = array();
  $endpoint->server_settings = array();
  $endpoint->resources = array(
      'myservice' => array(
        'operations' => array(
            'create' => array(
                'enabled' => '1',
            ),
        ),
      ),
  );
  $endpoint->debug = 1;
  $endpoints[] = $endpoint;
  return $endpoints;
}

In the services admin panel I have the resource and the crud operation enabled.

One related thing I should ask: there are 4 named items, endpoint, resource, service and endpoint path. Do all have to have different names?


Solution

  • It was the way I attempted to test. I completely spaced that I was testing a POST transaction and not a GET.

    FYI, the easiest way to test non-GET transactions are with a helper. For chrome, I downloaded Advanced Rest Client. Actually sending post data to a service configured to process POST is the best way to test it :)