LIST

  1. Define appropriate route.

    demo_photos-index:
       path:         api/demo/photos
       controller:   Vendor\Demo\Controller\PhotoApiController::index
       methods:      GET
       format:       json
       defaults:
          plugin:    PhotoApi
       options:
          middleware:
             - auth
    

    Tip

    index action has been already implemented in our predefined controller.

    GET 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.

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

  2. Use defined above endpoint in JavaScript scope.

    listResource('/api/demo/photos').then(function (entities) {
       console.log(entities);
    });
    

    Tip

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