Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By pratiikstha on
Hi all,
I am trying to use the Services Module to use Rest api (https://www.drupal.org/node/1871498). I have done all the steps that it requires.
But I am having some issue with this....I have done every step and it works for nodes....How can I use it in a custom module?
I have a data in an array in a method, and needs to produce a json response through an REST API.
Can you please help me with this?
Thank you :)
Comments
You need to implement hook
You need to implement hook_services_resources().
One more question!!!
Once I write the _services_resources method, how do I call it thru the postman or how can I test if it works?
The same way you would test
The same way you would test any rest service - get/post/put/delete to the resource, and see if you get a response. You mentioned postman - you can use that.
defined resource not listed in the Resources
Hi,
I defined one resource but the resource is not listed when I try to enable in Services. Can you please help me with it?
function mymodule_services_resource(){
$items = array();
//define resource
$item['get-infomation'] = array(
'mymodule' => array(
'index' => array(
'callback' => 'myfunction',
'args' => array(
array(
'name' => 'timestamp',
'type' => 'int',
'optional' => FALSE,
'description' => '',
'default value' => 0,
'source' => array('param' => 'timestamp'),
),
),
'access arguments' => array('access content'),
),
),
);
return $items;
}
I can't see my resource listed in the Edit resource in the {url}/admin/structure/services/list/api/resources
Your help is much appreciated!!!
I don't think you need this
I don't think you need this array:
'mymodule' => array(
I removed it but still not working
function mymodule_services_resource(){
$items = array();
//define resource
$item['get-infomation'] = array(
'index' => array(
'callback' => 'myfunction',
'args' => array(
array(
'name' => 'timestamp',
'type' => 'int',
'optional' => FALSE,
'description' => '',
'default value' => 0,
'source' => array('param' => 'timestamp'),
),
),
'access arguments' => array('access content'),
),
);
return $items;
}
Can you wrap your code in <
Can you wrap your code in <?php ?> tags? Too hard to read like that.
=-=
per https://www.drupal.org/node/643758 please edit your post and move it to the 'post installation' forum. Thank you.