READ

  1. Define appropriate route.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    demo_show:
       path:         api/demo/photos/{uid}
       controller:   Vendor\Demo\Controller\DemoApiController::show
       methods:      GET
       requirements:
          uid:        \d+
       options:
          middleware:
             - auth
    

    Tip

    show action has been already implemented in our predefined controller.

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

    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.

  2. Use defined above endpoint in JavaScript scope.

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

    Tip

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