REST/JSON
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
If you want to use this module, your options are:
- Choose another, actively maintained module instead
- File an issue in the queue with a patch to fix the module and then contact the security team to have your version reviewed and the project handed over to you following the unsupported project process.
- Hire someone to fix the security bug so the module can be re-published (see this guide on how to hire a Drupal site developer)
DISCLAIMER
This module is meant for DEVELOPERS who know how to customize to their need. It does NOT manage content permission, so if this is a concern for your site do not use this module.
REST/JSON
This module is a hassle-free tool to expose Drupal content via a REST/JSON interface.
It's designed for mobile apps, particularly for read-only Drupal backends and this means strong READ APIs and rough WRITE APIs.
Dependencies:
- entity: https://www.drupal.org/project/entity
- select_translation: https://www.drupal.org/project/select_translation
APIs
REST/JSON is meant to be as plug-and-play as possible, thus just enabling it you'll get the following APIs out-of-the-box:
* NODE APIs
- http://example.com/
- http://example.com/rest/node/
- http://example.com/rest/add/node/
For each node the APIs print all custom fields (i.e. fields starting with "field_" defined through the FieldsUI) and the
base fields configured in rest-config.inc.
If you want to add more fields, i.e. computed fields or non-trivial fields you can implement
- hook_rest_json_node_alter(&$nodew, $page) // $nodew is the entity wrapper of the node being printed
- hook_rest_json_node_add_alter(&$nodew) // $nodew is the entity wrapper of the node being added
* COMMENT APIs
- http://example.com/rest/add/coment/
For each comment the APIs print all custom fields (i.e. fields starting with "field_" defined through the FieldsUI) and the
base fields configured in rest-config.inc.
If you want to add more fields, i.e. computed fields or non-trivial fields you can implement
- hook_rest_json_comment_alter(&$commentw) // $commentw is the entity wrapper of the comment being printed
- hook_rest_json_comment_add_alter(&$commentw) // $commentw is the entity wrapper of the comment being added
* USER APIs
- http://example.com/rest/user/login: login API
- http://example.com/rest/user/logout: logout API
- http://example.com/rest/user/auth: check if user is logged
- http://example.com/rest/user/register: register new user
- http://example.com/rest/user/password/change: change password API
- http://example.com/rest/user/password/reset: send the reset link to the user
For each user the APIs print all custom fields (i.e. fields starting with "field_" defined through the FieldsUI) and the
base fields configured in rest-config.inc.
If you want to add more fields, i.e. computed fields or non-trivial fields you can implement
- hook_rest_json_user_alter(&$userw) // $userw is the entity wrapper of the user being printed
Consumer apps can login with the login API and save the session cookie. Subsequent logged APIs will read that cookie to authorize the user.
More documentation can be found in the live demo at http://dev.mobimentum.it/drupal-rest-json/
As you've seen so far, this is a module for developers, there's no UI here. Have a look at rest-config.inc, there are a few options to
customize, such as image format, fields to print, rest context and so on.
Custom APIs
Last but not least, there are a few functions that may be useful:
- rest_json_response($result, $bundle, $content, $message, $is_cached): useful if you want to implement a custom API endpoint, e.g.
function mymodule_custom_api() {
rest_json_response(FALSE, 'node', NULL, 'This is a custom message');
}