You are here

README.txt in Web Service Clients 7.3

Clients for Drupal Services REST Servers
==========================================

This module contains client connection types for connecting to Services module
on Drupal (http://drupal.org/project/services), for endpoints using the REST
server.

The remote Drupal site you are connecting to needs Services version 7.x-3.5 or
higher.

Setting up a client
--------------------

At admin/settings/clients, choose the type of connection you want to create.
The Drupal-specific options are as follows:

- Service username, password: the details for a Drupal user on the remote site.

It's a very good idea to go to the test page for your connection and try the
various actions such as logging in and retrieving a node. These show you exactly
what is returned from the remote server.

Setting up Services
------------------

Your Services endpoint must have:

- under 'Edit':
  - 'Session authentication' enabled
- under 'Server':
  - the 'json' response formatter enabled
  - the following Request parsing options enabled:
    - 'application/json'
    - 'application/x-www-form-urlencoded'
- under 'Resources
  - the user resource's login action enabled
  - the user resource's token action enabled
  - any other resources you want to use

API
-------------------

The parameters for clients_connection_call() are different from the XMLRPC
connections:

clients_connection_call(CONNECTION NAME, RESOURCE PATH, HTTP METHOD, DATA);

Examples:

try {
  // 'my_connection' is the machine name of the connection.
  $result = clients_connection_call('my_connection', 'node/1', 'GET');
}
catch (Exception $e) {
  // Something went wrong; it's up to you to display an error.
  // This is the error message, if any:
  $message = $e->getMessage();
}

Subsequent examples omit the try/catch block for brevity:

$result = clients_connection_call('my_connection', 'node/1', 'POST', $data);

You can also call the makeRequest() method on the connection:

$connection = clients_connection_load('my_connection');
$result = $connection->makeRequest('node/1', 'GET');

The 'user/register' service is a special case (and 'entity_user/register' if you
are using Services Entity). Functionally, this is identical in Services to
'user/create'. For both services, access is granted either if the
user is anonymous, or if the user has the 'administer users' permission (see
_user_resource_access()). To keep things simple, Clients assumes that for the
'user/register' services you intend to be anonymous, and for the 'user/create'
you are logging in as normal.

File

connections/clients_drupal_rest/README.txt
View source
  1. Clients for Drupal Services REST Servers
  2. ==========================================
  3. This module contains client connection types for connecting to Services module
  4. on Drupal (http://drupal.org/project/services), for endpoints using the REST
  5. server.
  6. The remote Drupal site you are connecting to needs Services version 7.x-3.5 or
  7. higher.
  8. Setting up a client
  9. --------------------
  10. At admin/settings/clients, choose the type of connection you want to create.
  11. The Drupal-specific options are as follows:
  12. - Service username, password: the details for a Drupal user on the remote site.
  13. It's a very good idea to go to the test page for your connection and try the
  14. various actions such as logging in and retrieving a node. These show you exactly
  15. what is returned from the remote server.
  16. Setting up Services
  17. ------------------
  18. Your Services endpoint must have:
  19. - under 'Edit':
  20. - 'Session authentication' enabled
  21. - under 'Server':
  22. - the 'json' response formatter enabled
  23. - the following Request parsing options enabled:
  24. - 'application/json'
  25. - 'application/x-www-form-urlencoded'
  26. - under 'Resources
  27. - the user resource's login action enabled
  28. - the user resource's token action enabled
  29. - any other resources you want to use
  30. API
  31. -------------------
  32. The parameters for clients_connection_call() are different from the XMLRPC
  33. connections:
  34. clients_connection_call(CONNECTION NAME, RESOURCE PATH, HTTP METHOD, DATA);
  35. Examples:
  36. try {
  37. // 'my_connection' is the machine name of the connection.
  38. $result = clients_connection_call('my_connection', 'node/1', 'GET');
  39. }
  40. catch (Exception $e) {
  41. // Something went wrong; it's up to you to display an error.
  42. // This is the error message, if any:
  43. $message = $e->getMessage();
  44. }
  45. Subsequent examples omit the try/catch block for brevity:
  46. $result = clients_connection_call('my_connection', 'node/1', 'POST', $data);
  47. You can also call the makeRequest() method on the connection:
  48. $connection = clients_connection_load('my_connection');
  49. $result = $connection->makeRequest('node/1', 'GET');
  50. The 'user/register' service is a special case (and 'entity_user/register' if you
  51. are using Services Entity). Functionally, this is identical in Services to
  52. 'user/create'. For both services, access is granted either if the
  53. user is anonymous, or if the user has the 'administer users' permission (see
  54. _user_resource_access()). To keep things simple, Clients assumes that for the
  55. 'user/register' services you intend to be anonymous, and for the 'user/create'
  56. you are logging in as normal.