Deleting Resources (DELETE)
How to delete JSON:API resources using NextDrupal.
⚠️
The deleteResource
helper is available in next-drupal ^1.4.0
.
If you're working with JSON:API, be mindful to select the option:
Accept all JSON:API create, read, update, and delete operations.
on the following path: /admin/config/services/jsonapi
in Drupal.
The NextDrupal
client ships with a deleteResource
method for deleting JSON:API resources.
deleteResource
Delete an article by id.
const deleted = await drupal.deleteResource( "node--article", "a937dd34-5407-4fff-8594-fccaaa5bb72a" // <-- Article ID)
See the API reference for deleteResource.
Authentication
To make authenticated requests when deleting resources, use the withAuth
option.
See the authentication docs for the supported authentication methods.
const deleted = await drupal.deleteResource( "node--article", "a937dd34-5407-4fff-8594-fccaaa5bb72a", { withAuth: // <-- Your auth method here. })