Building flexible web services using Drupal

Drupal can act as a RESTful API by using the Services module. We've come up with a novel approach to creating, maintaining and sharing service definitions and tests using a staged workflow that we call Kendra Builder.

Overview of Services and Kendra components

Kendra API

The Kendra API defines a set of resources for Drupal 7 Services, with corresponding access rules that define their availability via a ReSTful HTTP endpoint. The HTTP-based API supports multiple request/response formats, and can be modified in real time via updates to the method definitions, to adjust to the requirements of the project.

Well-defined methods, parameters, and response patterns are designed, documented and exported using the Kendra Builder. The API is then initialized with the output from the Kendra Builder using the Service Mapping Description format, a community proposal for a standardised profile of JSON Schema for describing a web service.

Employing a RESTful communications pattern utilizing HTTP methods for CRUD and index operations, Kendra API supports XML or JSON envelopes. Clients (e.g. widgets or instances of the SARACEN Terminal application) accessing the endpoint may use either the “application/xml” or “application/json” HTTP content-type for requests and responses.

Kendra API aims to implement basic features of the OpenSocial 2.0 API and Data Specifications (Core API Server, Core Data, Social API Server, Social Data). Core data types defined by these specifications include “People”, “Groups”, “MediaItems”, and “Albums” in addition to the complementary support for the “ActivityEntry” data type from the Activity Streams specification which was added in the version 2.0 of the Social Data specification.

Kendra Builder

Kendra Builder is a platform for creating, editing, and publishing an API and endpoint specification in a format suitable for pursuing standardisation. Leveraging and formalising the JSON Schema community proposal in order to provide a common interface for importing and exporting web-accessible resources, the platform comprises a suite of modules built on the Drupal framework. It is essentially an open-source platform for collaboratively building and editing the API resources with an interface that, in comparison to industry alternatives such as WSDL, is considerably streamlined and optimized for rapid development and collaboration.

Kendra Builder stores metadata specifications describing the content, user profiles and methods intended to be implemented by the Kendra API. It also assists in defining the workflow from the requirements specification to the technical implementation in one complete application. For example, individual specific requirements have been identified that are used as starting points for defining the right methodologies that should be used to meet the requirements of the system. However, a clear workflow has been defined and can be followed from the start to finish of the implementation.

Kendra Builder also allows for collaborative design between different participants contributing ideas, as it is purely accessible via a web browser. Integrated revision control allows for strict API versions to be released for parallel testing and production use.

Kendra Social

Kendra Social is a Drupal 7 installation profile which contains pretty much all you need to set up a hub for social networking.

Abstracting the parameters for integrating with various social network APIs, the Kendra Social subsystem provides a common interface for communicating with social networking services. Modular abstraction of methods to import and post content to various social networking APIs allows for a flexible base architecture that can be expanded to support future social networking platforms and functionality. Imported data from social network become part of a user’s profile. Internal mappings are therefore required in order to relate profile fields between different the various schemes employed on different social networks. Custom modules manage the service resource definitions, permissions integration, and user request brokering as well as implementation of all the various methods required for Terminal usage and OpenSocial compatibility.

The profile import process uses an intermediate format (RDF) to perform this mapping, where the mappings are defined as configuration parameters to Kendra Social and may be changed at runtime. The choice to create a prototype implementation of the API for user and media profile storage using Drupal 7 core, running on a standard web server stack of Linux, Apache, MySQL and PHP (LAMP) has allowed for rapid development of custom modules to implement project requirements. The advanced Drupal “core” framework and large variety of contributed modules collectively implement many common functions such as session management, OAuth-based authentication and authorisation, and JSON and XML parsing. Leveraging this robust platform allows developers to shift efforts from meeting fundamental SOA-related requirements to project-specific functionality.

Kendra API, Kendra Builder, and Kendra Social are free software developed by Kendra Foundation in collaboration with SARACEN and co-funded by the European Union. Sample code and the validation tool will be released under the GNU General Public License. Additionally, Kendra will Creative Commons license all of the API documentation, so users will be welcome to reuse and remix as appropriate.

Presentation

  • Services module
  • Short overview of what Services does
    • Won't go into details of services implementation, as the Kendra Builder abstracts many of those details
  • Concepts
    • Endpoints
    • REST
    • Request & response
  • Default services configuration
    • Default resources: node, taxonomy, etc.

Usage

  • Making requests
    • REST
    • JSON
    • XMLRPC
  • Service resource definitions
  • Mapping requests to drupal functions
  • Passing parameters and doing type checking
  • Access control
  • Service abstraction
  • Creating Services definitions
  • Exporting JSON-Schema or SMD
  • Documentation
  • Testing

Advanced usage

  • Integration with OAuth for authorisation

Case study: SARACEN

Also mention

  • OStatus
  • WebID

Acknowledgement

The research – carried out by Kendra Initiative – leading to these results has received funding from the European Union's Seventh Framework Programme (FP7/2007-2013) under grant agreement 248474 Socially Aware, collaboRative, scAlable Coding mEdia distributioN (SARACEN).

Speaking experience

Daniel Harris spoke at DrupalCon Paris 2009 on Using Drupal for Media Asset / Content Management, Semantic Syndication / Promotion and Commerce and has a long history of speaking at conferences for Kendra Initiative.

Experience level: 
Intermediate