API Development¶
We use the RESTful Web Services and OpenAPI REST Drupal modules to expose endpoints from Drupal as an API to be consumed by external parties.
Howtos¶
Create a new endpoint¶
- Implement a new REST resource plugin by extending
Drupal\rest\Plugin\ResourceBaseand annotating it with@RestResource - Describe
uri_paths,route_parametersandresponsesin the annotation as detailed as possible to create a strong specification. - Install the REST UI module
drush pm-enable restui - Enable and configure the new REST resource. It is important to use the
dpl_login_user_tokenauthentication provider for all resources which will be used by the frontend this will provide a library or user token by default. - Inspect the updated OpenAPI specification at
/openapi/rest?_format=jsonto ensure looks as intended - Run
task ci:openapi:validateto validate the updated OpenAPI specification - Run
task ci:openapi:downloadto download the updated OpenAPI specification - Uninstall the REST UI module
drush pm-uninstall restui - Export the updated configuration
drush config-export - Commit your changes including the updated configuration and
openapi.json