📑Schema

Example

Below is an example of a full schema with every action option and event including callback methods.

{
  options: {
    url: 'https://jsonplaceholder.typicode.com/todos/',
    method: 'post', // *GET, POST, PUT, DELETE
    headers: [{
      key: 'Content-Type',
      value: 'application/json'
    }],
    body: [{
      key: 'title',
      value: 'My todo item'
    }],
    mode: "cors", // no-cors, *cors, same-origin
    cache: "default", // *default, no-cache, reload, force-cache, only-if-cached
    credentials: "same-origin", // include, *same-origin, omit
    redirect: "follow", // manual, *follow, error
    referrerPolicy: "no-referrer-when-downgrade", // no-referrer, *no-referrer-when-downgrade, origin, 
  },
  events: {
    onRequestInit: {
      callback: async (fetchOptions, triggerEl) => {
        console.log(fetchOptions)
      }
    },
    onSuccess: {
      redirectUrl: null, // url e.g. https://example.com
      showElement: null, // element id e.g. #myElement
      hideElement: null, // element id
      callback: async (response, data) => {
        console.log(data)
      }
    }
    onError: {
      redirectUrl: null, // url
      showElement: null, // element id
      hideElement: null, // element id
      callback: async (response, data) => {
        console.log(data)
      }
    }
  }
}

Last updated