@edu-fe/api

1.2.0 • Public • Published

@edu-fe/api

Axios based client for edu-fe team

Installing

Using npm:

$ npm i @edu-fe/api

Using yarn:

$ yarn add @edu-fe/api

Dependencies

非小程序内使用Axios

小程序内调用wx.request

Api

create

api.create(url, [options])

返回Promise对象

create options

{
	// 是否缓存相应数据
	// 若使用缓存,则不会再次请求
	cache: fasle,
	
	// 是否需要校验登录状态
	// 如果需要登录,会调用前置登录方法
	checkLogin: false,
	
	// 是否需要发送formData
	// 尽在POST请求时可用
	formData: false,

    // baseURL
    baseURL: 'https://dynamicedu.wps.cn/API_V2'
	
	// 任何axios可用的选项
	...
}

createModule

api.createModule(module, [name])

未传入name,则注册到common组中

错误处理

请求发生异常时会返回状态为rejected的Promise对象,需要在调用时catch

Example

import api from '@edu-fe/api'

const module = {
	request: api.create('/')
}
api.createModule(module, 'example')
api.example.request()
	.then(res => {
		// TODO:
	})
	.catch(err => {
		// handle error
	})

Readme

Keywords

none

Package Sidebar

Install

npm i @edu-fe/api

Weekly Downloads

1

Version

1.2.0

License

none

Unpacked Size

5.75 kB

Total Files

8

Last publish

Collaborators

  • julywind
  • hungryyang
  • ccforeverd
  • shockw4ver