17
RESTful Web Services in Drupal 7

RESTful Web Services in Drupal7

  • Upload
    bmeme

  • View
    10.159

  • Download
    5

Embed Size (px)

Citation preview

Page 1: RESTful Web Services in Drupal7

RESTful Web Services in Drupal 7

Page 2: RESTful Web Services in Drupal7

‣ Web Services introduction‣ Why REST?‣ The Bricks: Drupal 7, Entity API, RESTful Web Services‣ Connector (REST client)‣ Let’s go coding...‣ Case Study‣ Questions?

RESTful Web Services in Drupal 7

Page 3: RESTful Web Services in Drupal7

ServiceRequester

ServiceProvider

SOAP, XML-RPC, REST, etc...

Web services

Page 4: RESTful Web Services in Drupal7

ServiceRequester

ServiceProvider

REST

Web services with Drupal

Page 5: RESTful Web Services in Drupal7

‣ Use standard HTTP (simple client and simple API)

‣ Multiple data formats (JSON, XML, etc...)

‣ Performance and scalability (Cacheable)

Why REST?

Page 6: RESTful Web Services in Drupal7

ServiceRequester

ServiceProvider

RESTDrupal 6

or

Drupal 7

Connector

Entity API

Drupal 7

RESTws

The bricks

Page 7: RESTful Web Services in Drupal7

This module extends the entity API of Drupal core in order to provide a unified way to deal with entities and their properties.

Additionally, it provides an entity CRUD controller, which helps simplifying the creation of new entity types.

http://drupal.org/project/entity

Entity API

Page 8: RESTful Web Services in Drupal7

Exposes Drupal resources (e.g. entities) as RESTful web services.

http://drupal.org/project/restws

‣ Provides only RESTful services.‣ Builds upon the Entity API, to provide support for all entity types out of the box.‣ Currently only CRUD operations supported‣ Currently JSON, XML and RDF/XML are available out of the box.‣ There are no "service endpoints" to configure as resources are just available at uniform paths like "node/1", "user/1".

RESTful Web Services

Page 9: RESTful Web Services in Drupal7

To obtain the JSON representation of an entity use your browser to visit:

http://yoursite.com/node/1.json orhttp://yoursite.com/user/1.json orhttp://yoursite.com/<entity type name>/<entity id>.json

Note: The module will respect your access permissions, so make sure you are logged in.

RESTful Web Services: Test it!

Page 10: RESTful Web Services in Drupal7

Supports full CRUD (Create, Read, Update, Delete) for resources:

‣ Create: HTTP PUT /<entity type name> (requires HTTP Content-Type header set to the MIME type of <format>)‣ Read: HTTP GET /<entity type name>/<entity id>.<format> or HTTP GET /<entity type name>/<entity id> (requires HTTP Accept header set to the MIME type of <format>)‣ Update: HTTP POST /<entity type name>/<entity id>.<format> or HTTP POST /<entity type name>/<entity id> (requires HTTP Content-Type header set to the MIME type of the posted format)‣ Delete: HTTP DELETE /<entity type name>/<entity id>

Note: The representation <format> can be json, xml etc.

RESTful Web Services: CRUD

Page 11: RESTful Web Services in Drupal7

‣ Authentication can be achieved via separate modules, maybe making use of the standard Drupal cookie and session handling.

‣ The module comes with an optional HTTP Basic Authentication module (restws_auth_basic) that performs a user login with the credentials provided via the usual HTTP headers.

‣ The usual Drupal permission system is respected, thus permissions are checked for the logged in user account of the received requests.

RESTful Web Services: Auth and Perms

Page 12: RESTful Web Services in Drupal7

Connector: REST Client

Page 13: RESTful Web Services in Drupal7

Connector: Example (webform hook)

Page 14: RESTful Web Services in Drupal7

Connector: Example (response)

Page 15: RESTful Web Services in Drupal7

ServiceRequester

ServiceProvider

REST

Pamm Travel(Drupal 6)

Tikal(Drupal 7)

Case Study

Page 16: RESTful Web Services in Drupal7

ServiceRequester

ServiceProvider

REST

Intersos(Drupal 6)

Tikal(Drupal 7)

Case Study