npm.io
0.2.1 • Published 4 years ago

brick-axios

Licence
MIT
Version
0.2.1
Deps
2
Size
15 kB
Vulns
0
Weekly
0

brick-axios

基于brick-engineaxios工具包.

Install

npm install --save brick-axios
npm install --save axios

Usage

Setup


const {defineApplication} = require('brick-engine');
const {axiosSetup} = require('brick-axios');

const app = {};

axiosSetup(app);
defineApplication(exports, app);

Define Axios Instance


const { defineAxios } = require('brick-axios');
const { AXIOS_ID } = require('./constants');

class Module {
    
}

exports.Module = Module;
defineAxios(Module,{id:AXIOS_ID,config:{baseURL:'http://localhost'}});

Use Axios Instance


const { AXIOS_ID } = require('./constants');
const { defineProviderFactory } = require('brick-engine');

class Service {

    constructor(axios) {
        this.axios = axios;
    }

    async create(entity){
        const res = await this.axios.post('/simple');
        return res.data;
    }
}

exports.Service = Service;
defineProviderFactory(Service,{deps:[{id:AXIOS_ID}]});

Documentations

使用jsdoc生成注释文档

git clone https://github.com/kiba-zhao/brick-axios.git
cd brick-axios
npm install
npm run docs
open docs/index.html

License

MIT

Keywords