Advertising sustains the DA. Ads are hidden for members. Join today

Contributed modules documentation

RESTful Web Services

RESTWS exposes Drupal resources (e.g. entities) as RESTful web services. The module makes use of the Entity API and the information about entity properties (provided via hook_entity_property_info()) to provide resource representations.

It aims to be fully compliant to the REST principles.

Installing the Module

  • Copy the whole restws directory to your modules directory (e.g. DRUPAL_ROOT/sites/all/modules) and activate the RESTful Web Services module.
  • Use Drush commands: drush en restws
  • There is no user interface to configure.

Usage / Testing

To obtain the JSON representation of an entity use your browser to visit: http://example.com/<entity type name>/<entity id>.json
For example: http://example.com/node/1.json or http://example.com/user/1.json would resolve as a JSON dump to client. There are no "service endpoints" to configure as resources are just available at uniform paths like "node/1", "user/1". One can use a client in the form of a browser plugin to test out the different CRUD functions.

Filtering / Querying

You can filter for certain resources by passing parameters in the URL, for example to retrieve all nodes of a certain node type, or all taxonomy terms in a specified vocabulary.

Query format:

HTTP GET /<entity type name>.<format>?<filter>=<value1>&<meta_control>=<value2>

Examples:

/node.json?type=article will return all "article" nodes
/taxonomy_term.json?vocabulary=7 will return all terms in vocabulary 7

See the module README.txt for further details.

Permissions

In order to access entities via this interface, permissions must be granted for the desired operation (e.g. "access content" or "create content" for nodes).
Additionally each resource is protected with a RESTWS permission that can be configured at "admin/people/permissions#module-restws".

Additional Resources

Browser Plugins & Software for Testing

HTTP Basic Authentication for RESTful Web Services

This is a plain copy/paste job of the README file from the restws_basic_auth submodule of the RESTful Web Services for Drupal (restws)

OAuth authentication (Drupal 7)

voxpelli wrote some code illustrating how to implement client-side authentication with the OAuth module and Http Client:

Guide maintainers

saltednut's picture