Skip to content

Instantly share code, notes, and snippets.

@sveggiani
Last active September 5, 2017 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sveggiani/54444b645bc7fd0ec60c2f70050edc5d to your computer and use it in GitHub Desktop.
Save sveggiani/54444b645bc7fd0ec60c2f70050edc5d to your computer and use it in GitHub Desktop.
Drupal - RESTful Webservices API #drupal #restful #webservices #cms

Drupal RESTful Webservices API

Características

Implementación

  1. Instalar módulos del core: HAL, HTTP Basic Authentication, RESTful Web Services, Serialization
  2. Instalar módulos contribuidos (opcional): REST UI. Este módulo provee una UI para habilitar y desabilitar recursos, adminsitrar los formatos de serialización y Auth providers.
  3. Crear un rol: por ej. API user
  4. Setear permisos para el rol:
  • Anonymous: GET
  • Authenticated User: GET, DELETE, POST, PATCH
  1. Crear usuario: por ej. API_consumer/API_consumer
  2. Setear permisos sobre el contenido que se desea manejar: ej. Basic Page.
  3. Demo time

Información relacionada

Recursos auxiliares:

HAL

hypermedia driven: The rationale behind this principle is that all possible operations with the resource can be discovered without the need of any out-of-band documentation and if some URI changes, there is no need to change the client as it is server's responsibility to generate URIs and insert them into representations.

Hypertext Application Language (HAL) is one possible recipe how to do design representations with links. In particular, it describes how to design JSON representations.

There is a convenient way to tell whether an API is RESTful or not. A so-called Richardson Maturity Model (RMM) was introduced by Leonard Richardson in his 2008 QCon talk and later popularized by Martin Fowler. The model introduces four levels of API maturity starting from Level 0, so that at level two each resource is not only identified by its own URI, but all operations with resources are done using HTTP methods like GET, PUT etc.

{
    "_links":{
        "self":{
            "href":"/book/123"
        },
        "curries":[
            {
                "name":"ns",
                "href":"http://booklistapi.com/rels/{rel}",
                "templated":true
            }
        ],
        "ns:authors":[
            {
                "href":"/author/4554",
                "title":"Leonard Richardson"
            },
            {
                "href":"/author/5758",
                "title":"Mike Amundsen"
            },
            {
                "href":"/author/6853",
                "title":"Sam Ruby"
            }
        ]
    },
    "Title":"RESTful Web APIs",
    "Price":"$31.92",
    "Paperback":"408 pages",
    "Language":"English"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment