# Chimera Instance

Chimera instance manages all endpoints.

  • Send endpoint requests that has auto property true
  • Cancel endpoint requests on vue component destroy
  • Instantiate endpoints based on defaults set on it
  • Update reactive endpoints
  • Provide some globals like $loading, $axios, $cancelAll()

# Endpoint defaults

To set some defaults to endpoint definitions use $options property on chimera option:

export default {
    chimera: {
       $options: {
          // Pass an axios instance with it's defaults
          axios: axios.create(),

          // Or
          baseURL: 'http://my-api.com/api/',
          headers: {
             'X-Sample-Header': 'Header'
          },
       },
       
       posts: {
           url: '/posts'
       }
    }
}

Note : Chimera options can also be set globally on plugin options. See Installation

# Access current vue instance

Sometimes to define the defaults for endpoints, You need to access current vue instance (usually with this)

Simply you can use a function that returns these options:

export default {
    // Chimera as a function
    chimera () {
        return {
          $options: {
             // Pass injected axios as http client
             axios: this.$axios,
          },
          
          // Use route parameters
          post: {
              url: '/posts/' + this.$route.params.id
          }
       }
    }
}

# Global chimera properties and methods

There are some useful global props prepending with $. This is the reason why you cannot define endpoint with name starting with $

  • $chimera.$loading

    Global loading indicator, returns true if there's any endpoint in loading state

  • $chimera.$cancelAll()

    Global method that cancels all pending requests

Last Updated: 3/20/2020, 12:15:01 PM