Jul 29, 2019, 4:33:31 PM

API Client

Frontless makes use of Feathers.JS Client because it works the same way in any environment. There are two general ways to call API methods from the application:

1. Unauthorized mode

API Client imported directly from the module is not authorized:

import 'client' from 'client'

const Model = client.service('/myservice')

Model.create({message: 'hello!'}).then((res)=>{
  alert('Message created!')
})

2. Authorized mode

Frontless provides a Riot.JS plugin to make authorized API requests:

<my-component>
  <div>{state.value}</div>
  <script>
    export default () => ({
      state: {
        value: ''
      },
      createItem(data){
        const Model = this.client.service('items')
        Model.create(data)
      }
    })
  </script>
</my-component>

The plugin makes authorized requests that work on the server and browser.