Example: REST
Same name in other branches
- 3.x modules/rest_example/rest_example.module \rest_example
This module will give you a brief demonstration of how the REST service works.
This example uses nodes, because they works out of the box. But any entity could be used.
To complete a demo, we'll need a server site, containing the nodes, and a client, that sends requests to the server. The same site can very well act as both client and server.
First thing you want to do, is visit 'examples/rest-client-settings' and setup what website you want to interact with. To avoid complications, and minimize the chance of failure, I'll suggest that you start using the same site as both server and client, using the user 1 credentials. And when you have gotten the feel of how things work, try to use two separate sites, and maybe another user. Please note that you need to install this module on both client and server site.
Next thing you want is to go to 'examples/rest-client-actions'. This page contains a table where all the remote nodes, of the type rest_example_test, will be displayed. At first there might not be any.
From the same page you can create, edit and delete nodes on the remote site.
The server site actually only uses the View (rest_service) and the node type (rest_example_test), imported upon installation of this module. The rest of the functionality comes from Drupal Core modules, like 'rest', 'basic_auth' and 'hal'.
The client part of the site uses the following classes:
See also
\Drupal\rest_example\Controller\RestExampleClientController::indexAction() Builds the list of nodes on the remote server.
- @see \Drupal\rest_example\Form\RestExampleClientSettings A form that can creates/edits nodes.
- @see \Drupal\rest_example\Form\RestExampleClientSettings A form used to confirm the deletion of the node.
- @see \Drupal\rest_example\Form\RestExampleClientSettings A form where you set up with which site you want to interact.
- @see \Drupal\rest_example\RestExampleClientCalls This class handles all the calls to the remote site, and returns the response back, to be processed by the requesting method.
Parent topics
File
-
modules/
rest_example/ rest_example.module, line 8
Classes
Title Sort descending | File name | Summary |
---|---|---|
RestExampleActionTest | modules/ |
Verify that the Views are accessible. |
RestExampleClientController | modules/ |
Controller class for the REST Example routes. |
RestExampleClientDelete | modules/ |
Delete a new node on a remote Drupal site. |
RestExampleClientEdit | modules/ |
Edit or create a new node on a remote Drupal site. |
RestExampleClientSettings | modules/ |
Setup form for a Drupal REST client. |
RestExampleHelpController | modules/ |
Provides a help page for the REST Examples module. |
RestExampleMenuTest | modules/ |
Test the user-facing menus in Rest Example. |
RestExampleSettingsTest | modules/ |
Test the settings in Rest Example. |