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\ResourceBase
and annotating it with@RestResource
- Describe
uri_paths
,route_parameters
andresponses
in 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_token
authentication 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=json
to ensure looks as intended - Run
task ci:openapi:validate
to validate the updated OpenAPI specification - Run
task ci:openapi:download
to 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