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 inapi
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)