Services 7.3 - Simple Resource Example works only with GET not with POST from Poster

drupal.stackexchange https://drupal.stackexchange.com/questions/11031

  •  16-10-2019
  •  | 
  •  

Question

I created a very simple test service here is the code, for some reason only GET works with it in Firefox Poster, but POST returns a 404 Controller not found. Any tips? Here is what works http://mysite.com/services/myendpoint/mytest/retrieve/

with parameter of id = 1

<?php

/**
 * Implementation of hook_services_resources().
 */
function mytest_services_resources() {
  return array(
   'mytest' => array(
     'retrieve' => array(
       'help' => 'Retrievs a test',
       'callback' => '_mytest_retrieve',
       'args' => array(
         array(
           'name' => 'id',
           'type' => 'int',
           'description' => 'The id of the test to get',
           'source' => array('path' => '0'),
           'optional' => FALSE,
         ),
       ),
     ),
   ),
  );
}

/**
 * Callback for creating  resources.
 *
 * @param object $data
 * @return object
 */
function _mytest_retrieve($id) {
  return "READY TESTING";
}


?>
Was it helpful?

Solution

You need separate callbacks for each of the CRUD operations. You've only implemented 'retrieve', which is the GET callback, you need to implement a 'create' callback for POST to function.

Reading the docs really helps: https://drupal.org/node/783460

OTHER TIPS

you can't POST for any retrieve method.

Post is only for actions, and create methods.

you can read WAY more about it here. http://drupal.org/node/783254

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top