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

Jaypan’s picture

You need to implement hook_services_resources().

pratiikstha’s picture

Once I write the _services_resources method, how do I call it thru the postman or how can I test if it works?

Jaypan’s picture

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.

pratiikstha’s picture

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!!!

Jaypan’s picture

I don't think you need this array:

'mymodule' => array(

pratiikstha’s picture

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;
}

Jaypan’s picture

Can you wrap your code in <?php ?> tags? Too hard to read like that.

VM’s picture

per https://www.drupal.org/node/643758 please edit your post and move it to the 'post installation' forum. Thank you.