azrequests

1.1.0 • Public • Published

azrequests

axios

if you have any question,you can visit my github site and submit issue ,you are welcome

Now Data structures that support custom return values

{
    code:"success",
    msg:null,
    data:{}
}
or
{
    code:200,
    msg:"success",
    data:{}
}
etc

Installation

npm i azrequests -S

Usage in components

import azrequests from 'azrequests';
Vue.prototype.$http = azrequests;
 
this.$http(
    {
    url: 'http://v.juhe.cn/toutiao/index?type=shehui&key=925021c32be17cac549273a63f0d02be',
    param: {
        type: 'shehui'
    },
    dataStructure: {
        code: 'error_code',
        data: 'result',
        msg: 'error_code'
    },
    condition: 0
}
    ).handlData(callback(res,err),method)

Usage in non-components

let azrequests = require('azrequests')
azrequests(
    {
    url: 'http://v.juhe.cn/toutiao/index?type=shehui&key=925021c32be17cac549273a63f0d02be',
    param: {
        type: 'shehui'
    },
    dataStructure: {
        code: 'error_code',
        data: 'result',
        msg: 'error_code'
    },
    condition: 0
}headers:null
    }
    ).handlData(callback(res,err),method)

Example

Performing a POST request

// Make a request for news with a given type
azrequests({
    url: 'http://v.juhe.cn/toutiao/index?type=shehui&key=925021c32be17cac549273a63f0d02be',
    param: {
        type: 'shehui'
    },
    dataStructure: {
        code: 'error_code',
        data: 'result',
        msg: 'error_code'
    },
    condition: 0
}).handlData((res, err) => {
    console.log('res: ', res);
},'post')
 

Performing a GET request

// Make a request for news with a given type
azrequests({
    url: 'http://v.juhe.cn/toutiao/index?type=shehui&key=925021c32be17cac549273a63f0d02be',
    param: {
        type: 'shehui'
    },
    dataStructure: {
        code: 'error_code',
        data: 'result',
        msg: 'error_code'
    },
    condition: 0
}).handlData((res, err) => {
    console.log('res: ', res);
},'get')

API

变量名 描述 默认值
url 接口地址 必选 String :eg:“https://api.apiopen.top/recommendPoetry”
param 请求参数 必选 String or Object
type 数据类型 可选 "formData" default:‘json’
headers 请求头 可选
condition 成功的判断条件 可选 默认:"success" eg:condition = 200
method 请求方式 必选 默认值:'post' ‘get’or‘post’
callback 回调函数 res返回值,err错误信息
dataStructure 数据结构 默认{code,data,msg}

License

MIT Copyright (c) 2019-present, azrequests

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.00latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.00
1.0.400
1.0.380
1.0.370
1.0.360
1.0.350
1.0.340
1.0.330
1.0.320
1.0.310
1.0.300
1.0.290
1.0.280
1.0.270
1.0.250
1.0.230
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.160
1.0.150
1.0.130
1.0.120
1.0.110
1.0.100
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i azrequests

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

13.1 kB

Total Files

7

Last publish

Collaborators

  • happypot