CREATE

  1. Define appropriate route.

    demo_photos-store:
      path:         api/demo/photos
      controller:   Vendor\Demo\Controller\PhotoApiController::store
      methods:      POST
      format:       json
      defaults:
        plugin:     PhotoApi
        data:
      options:
        middleware:
          - auth
          - LMS\Routes\Middleware\Api\Throttle:10,1
    

    Tip

    store action has been already implemented in our predefined controller.

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

    data is required argument here, as we later pass data that will be placed inside data argument.

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

    Throttle It’s optional, but quite useful. Usually we want to limit creation of certain recourse per time.

  2. Use defined above endpoint in JavaScript scope.

    storeResource('/api/demo/photos', {title: 'My new entity'}).then(function (isOk) {
        console.log(isOk);
    });
    

Tip

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