8
Creating a custom API for a headless Drupal Alberto G. Viu [email protected]

Creating a custom API for a headless Drupal

  • Upload
    exove

  • View
    809

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Creating a custom API for a headless Drupal

Creating a custom API for a headless Drupal

Alberto G. Viu [email protected]

Page 2: Creating a custom API for a headless Drupal

What is a headless Drupal?

Drupal Back-end

Drupal Head (Theming)

CLIENT

SERVER

Traditional Drupal stack Runs in Headless Drupal

Drupal Back-end

Client Apps

Drupal API

Page 3: Creating a custom API for a headless Drupal

Why headless Drupal?

● Installation is easier to maintain (no rendering to take care of)● Due to that, performance is much better● Easier to work with different teams

Because client-side frontend frameworks are the future of the web

Also it comes with some advantages:

Clients that could use the API:● Other Drupal sites● Mobile apps● Flash components● Other servers and services● Internet of things

Page 4: Creating a custom API for a headless Drupal

How to create the API?

● Drupal community provides four major solutions.

● Views Datasource● You don't need any code at all● Configured by UI● … but very limited.

● RestWS● REST Web Services● Contrib in D7, in core in D8● Wrappers EntityAPI

Page 5: Creating a custom API for a headless Drupal

How to create the API? (II)

● Restful● Newest in town● Best practices for security, performance and usability● Extremely developer oriented (site builders, go away)

● Services● Framework for creating custom API's● Introduces endpoints, key for creating custom paths● Ships with basic entities resources created.● Allows create other server such as SOAP.● Lots of extensions: views, rules, Search API, Authentication...

Page 6: Creating a custom API for a headless Drupal

How to use Services?

● Services module introduces two concepts: endpoints and resources.

● Endpoints● Defines a custom path● Defines authentication mode● Attach resources to them● Exportable

● Resources● CRUD operations● Fixed path pattern for the CRUD operations● Actions: Global (e.g. Solr reindex)● Targeted actions (e.g. publish node)● Relationships (e.g. retrieve comments from node)

Page 7: Creating a custom API for a headless Drupal

Schema of a resource

● CRUD:● Create: POST /endpoint/resource/ + body data● Retrieve: GET /endpoint/resource/id● Update: PUT /endpoint/resource/id + body data● Delete: DELETE /endpoint/resource/id● Index: GET /endpoint/resource/

● Actions: ● POST /endpoint/resource/my_custom_action

● Targeted actions:● POST /endpoint/resource/id/my_targeted_action

● Relationships:● GET /endpoint/resource/id/related_content

Page 8: Creating a custom API for a headless Drupal

Thank you

[email protected]