Voting starts in March for the Drupal Association Board election.
After you have installed the Services module and created a service, you can test whether it is working by enabling a resource and retrieving that resource. During initial testing, it will make your life easier if you disable all authentication. You can enable the authentication later after you have confirmed that the service you have created is returning results as expected.
For the purpose of this test, we will assume that you have created a service named "test_service" with an endpoint of "test" and a REST server. We will also assume that you have not yet enabled any authentication. If you edit your service at /admin/structure/services/list/test_service you should therefore see something like this:
Using the node resource for testing is a good way to get started because creating nodes is easy in Drupal and because the Services module provides the full range of CRUD methods for nodes: create, retrieve, update, delete (and index).
1. Make sure anonymous users have permission to view nodes
Since you have not enabled authentication, Services has no way of associating your request with a user ID and will treat all requests as coming from an anonymous user. In order to retrieve node information, therefore, the "View published content" permission must be enabled at admin/people/permissions.
2. Figure out the path for your node resources
The next thing you'll need to do to test your resource is figure out what path it lives under. This is put together from several pieces of information you entered into the Services admin screens. The formula is
Additionally, you can specify the response format that you want returned by adding a period followed by the abbreviation for that response format to the end of the URL. If no response format is specified, XML is is the default (assuming that your service has XML enabled).
Your endpoint path was defined when you followed the steps to "add a new endpoint." (See Services Installation and Setup.) To get your resource path, edit your endpoint, and click the "Resources" tab as shown in the screenshot below. Each available resource will be listed, with boxes checked for each resource that you have enabled. Look for the "node" resource and see if anything is entered for its "alias." If no alias is entered, then the name of the resource will be the resource path. Otherwise, the alias will be the resource path.
3. Test the node retrieve and node index methods
The Services module's RESTful interface uses the HTTP GET method to submit "retrieve" and "index" requests, so they are the easiest REST queries to test directly from your web browser. To test the "create" methods you will need to use an HTTP POST method. To test the "update" method will require an HTTP PUT method, and the "delete" method requires HTTP DELETE. It takes a little more effort to put together POST, PUT and DELETE methods, so we'll start by testing some "retrieve" and "index" requests.
Examples: Let's assume that you want to get an list of nodes your resource using the endpoint path defined above as "test." and you want to retrieve node resources. If you want the result to come back formatted as XML, the URL for a "index" request to retrieve a list of nodes would therefore be:
If you want the result as JSON, the URL for this request would be:
To get a single node with node id of 5, the URLs above would become:
or for JSON:
If you visit the URLs listed above in your browser, you should receive responses in XML and JSON as specified. If you get a Page Not Found error, you have something wrong.
Once you have confirmed that your request is returning the result you expected, go ahead and test other node resource queries. The results that come back will be limited by the permissions you have enabled for anonymous users. For example, if you turn off the "View published content" permission for anonymous users, you will get a response of "Access denied for user anonymous" when you try the URLs above.
4. Testing node creation, updating and deletion
As noted above, HTTP methods other than HTTP GET are needed to create, update and delete resources via a RESTful interface. A number of plug-ins are available that make it easier to test the HTTP PUSH, HTTP POST and HTTP DELETE methods via different web browsers, including the following:
- The Poster add-on for Firefox.
- The RESTClient add-on for Firefox.
- The HttpRequester add-on for Firefox.
- The REST Console app for Chrome.
- The Postman REST Client for Chrome.
A number of documentation pages have been created with code samples that show how to implement requests to Services, including the following:
- Example REST server for node.create with session authentication (JSON & PHP cURL)
- Example XMLRPC POST for node.create
Each example assumes a specific choice for the format in which a request is submitted, which affects request parsing, as well as the format for the response that gets sent back to the requester. Further information about those choices can be found in the documentation for Services response formatters and request parsing.
- The HTTP Client module provides a client library for Drupal that is designed to work with Services.
- The Drupal_http_request() function, which is part of Drupal core, also provides functionality for submitting HTTP requests.
- Guzzle HTTP client for PHP
- RESTClient, a Java application.
- HTTP4e, a REST HTTP client for Eclipse.
- HTTP Client, Mac OS X developer tool for debugging HTTP services by graphically creating and inspecting complex HTTP messages.
- cURL command line client.
- Services 3 - POST node.create with custom fields
- RESTful Web Services by Leonard Richardson and Sam Ruby (O'Reilly Media), May 2007.
Drupanium API documentation for different resources. It includes the right URL, parameters, how a response would look and more.Dead link?
- Services Sandbox. Testing resources on a test server