Slides from our talk “REST in Peace” for DrupalCamp Baltics 2015: http://drupalcampbaltics.com/event/rest-peace
Speakers:
- Kate Marshalkina
- Konstantin Komelin
Speech transcript is available here: http://komelin.com/en/articles/rest-peace-api-development-drupal
2. Kate Marshalkina
Konstantin Komelin
Drupal Consultant from Moscow who fell in
love with Drupal in 2011.
Interested in i18n, distributions and Drupal 8.
Path Breadcrumbs co-maintainer.
@kalabro
Drupal Consultant from Saint Petersburg
Co-founder of local Drupal Community
Drupal Trainer at MorningCurve
@kkomelin
17. Endpoint
https://www.drupal.org/project/endpoint
“Endpoint is really light, fast and flexible, that makes it a good solution
for projects where Drupal role is mobile backend and single-page app
backend.”
7 sites use this module.
Popularity: ★
REST-focused alternative to High-performance JavaScript callback handler
https://www.drupal.org/project/js
18. Drupal 8 REST
Core + https://www.drupal.org/project/restui
“In Drupal 8 core, interactions with content
entities are supported via a REST interface.
The REST module is extensible, and
modules that wish to offer other services
can implement Resource Plugins.”
Popularity: ★★
19. Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
20.
21. Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
29. RestWS
Entity API + 7 hooks
To create a custom resource:
1. Implement hook_restws_resource_info()
2. Create controller class on top of RestWSResourceControllerInterface
30. RESTful
Ctools plugins, Entity API, OOP
To create a custom resource:
1. Implement hook_ctools_plugin_directory ()
2. Create controller class on top of RestfulEntityBase / RestfulInterface
31. Endpoint
Custom routing function.
To create a custom resource:
1. Create /api.php with an array of endpoints.
2. Call endpoint_route() from that file.
32. Drupal 8 REST
Plugin Manager, Config Manager, Routes, Annotations etc.
To create a custom resource:
1. Create controller on top of ResourceBase / ResourceInterface.
2. Save it as src/Plugin/rest/resource/MyCustomResource.php inside your module.
To enable endpoint for existing resource:
1. Write/paste resource settings into rest.settings.yml.
2. Create config/install/rest.settings.yml inside your module.
33. Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
43. How did we count?
• Ubuntu 14.04, Nginx 1.8.0, Mariadb 10.0.20, PHP 5.5.9 with php5-fpm, 1GB RAM
• Minimal Drupal Profile
• Node with just Title and Body
• Disabled Drupal cache
• Anonymous requests
• HTTP POST to create entities
• Apache Benchmark (ab)
• Clean database after each ab run
44.
45.
46. Services RestWS RESTful Endpoint Drupal 8
Popularity
Documentation
Extensibility
Authentication
Performance
Auto API Docs
Versioning
59. Bonus: Drupal as an API Client
1. drupal_http_request()/ curl_exec()
2. RESTClient — Wrapper for 1.
3. Guzzle — PHP HTTP client
4. Feeds — for GET only
5. Clients — Pluggable client, supports Services endpoints
6. Remote Entity — Entity API + Clients
7. WSData — Alternative to Remote Entity
8. Integration with popular APIs: Twitter, Facebook, Dropbox etc.
9. Saucier — A Node.JS framework for Drupal API consumption.