DELETE

  1. Define appropriate route.

    demo_photos-destroy:
       path:         api/demo/photos/{uid}
       controller:   Vendor\Demo\Controller\PhotoApiController::destroy
       methods:      DELETE
       format:       json
       defaults:
          plugin:    PhotoApi
       requirements:
          uid:       \d+
       options:
          middleware:
             - auth
    

    Warning

    If you extend LMSFacadeControllerAbstractApiController,

    uid must be present and it’s name should not be changed.

    Tip

    destroy action has been already implemented in our predefined controller.

    DELETE is not required, but as we follow the concept, we should always use it.

    json is not required, but it gives a little bit of clarity.

    requirements has uid argument and tells us it must be of type integer.

    auth FE user session is required as well as proper csrf token.

    See also

    When the resource must be deleted only by it’s creator or limited number of users see

  2. Use defined above endpoint in JavaScript scope.

    deleteResource('/api/demo/photos/1').then(function (isOk) {
       console.log(isOk);
    });
    

    Tip

    deleteResource function has been already implemented in our predefined Routes.js.