Integrating third-party applications using REST and related operations.
Web services make it possible for applications and web sites to read and update information from other web sites. There are several standard techniques for providing web services, including:
Drupal sites can both provide web services and integrate third-party web services.
The REST technique uses basic HTTP requests to obtain and update data, where each web service defines a specific API (HTTP GET and/or POST parameters and returned response) for its HTTP requests. REST requests are separated into several types, known as methods, including:
The Drupal Core REST module provides support for GET, POST, PATCH, and DELETE quests on entities, GET requests on the database log from the Database Logging module, and a plugin framework for providing REST support for other data and other methods.
REST requests can be authenticated. The Drupal Core Basic Auth module provides authentication using the HTTP Basic protocol; the contributed module OAuth (https://www.drupal.org/project/oauth) implements the OAuth authentication protocol. You can also use cookie-based authentication, which would require users to be logged into the Drupal site while using the application on the third-party site that is using the REST service.
Here are the steps to take to use the REST operations provided by Drupal Core:
For more detailed information on setting up REST, see https://www.drupal.org/documentation/modules/rest.
The REST framework in the REST module has support built in for entities, but it is also an extensible plugin-based system. REST plugins implement interface \Drupal\rest\Plugin\ResourceInterface, and generally extend base class \Drupal\rest\Plugin\ResourceBase. They are annotated with \Drupal\rest\Annotation\RestResource annotation, and must be in plugin namespace subdirectory Plugin\rest\resource. For more information on how to create plugins, see the Plugin API topic.
If you create a new REST plugin, you will also need to enable it by providing default configuration or configuration import, as outlined in Enabling REST for entities and the log above.
If you want to integrate data from other web sites into Drupal, here are some notes:
Name | Location | Description |
---|---|---|
Json | core/lib/Drupal/Component/Serialization/Json.php | Default serialization for JSON. |
ResourceBase | core/modules/rest/src/Plugin/ResourceBase.php | Common base class for resource plugins. |
RestResource | core/modules/rest/src/Annotation/RestResource.php | Defines a REST resource annotation object. |
Name | Location | Description |
---|---|---|
ResourceInterface | core/modules/rest/src/Plugin/ResourceInterface.php | Specifies the publicly available methods of a resource plugin. |
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!core.api.php/group/third_party/8.1.x