Skip to main content

Custom API Helper

Badaso provides a axios based utility for calling an API. The difference is that resource have inserted headers such as authorization and content-type. Here is an example of calling the API.

import Vue from 'vue'
Vue.prototype.$resource.get(url); /** equal axios.get(url) **/

Badaso also supports for customization API helper. The block below is a directory structure for adding a new API helper.

Add an API Helper#

  • To add an API helper, add it to the modules directory in api directory.
๐Ÿ“ฆ Your Projectโ”ฃ ๐Ÿ“‚ resourcesโ”ƒ โ”ฃ ๐Ÿ“‚ jsโ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚ badasoโ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚ apiโ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œ example-api.js
  • Below is an example of HTTP request method that you can use.
example(data = {}) {  let ep = '/example';  let qs = QueryString(data);  let url = ep + qs;  return Vue.prototype.$resource.get(url);},
example(data) {  return Vue.prototype.$resource.post('/example', data);},
example(data) {  return Vue.prototype.$resource.put('/example', data);},
example(data) {  return Vue.prototype.$resource.patch('/example', data);},
example(data) {  let paramData = {    data: data,  };  return Vue.prototype.$resource.delete('/example', paramData);},
  • Here is the example of using the custom API helper.
$api.exampleApi.example(data)
this.$api.exampleApi.example(data)