fetch-request-method
v0.0.3
Published
this is a project of send fetch request
Downloads
9
Readme
项目介绍
业务封装fetch api进行请求
人员
- zhengchaopeng
使用方法
import request from 'fetch-request-method';
/**
* RDA middlewares can be a sync or async method,
* input params is request context, contains origin param of invoke
* and datas mounted by other middlewares, as we due:
* `options.api`: fetch url
* `options.type`: fetch type, like jsonp, ajax, native, etc.
* `options.query`: the final request params (maybe handled by query-formatters)
* `options.headers`: request headers for fetch
* `options.body`: the final response (maybe handled by data-formatters)
* `options.message`: error message
* `options.meta`: an object for middlewares, contains meta data, like timeout, delay, etc.
* `options.method`: request method, like GET, PUT, POST, DELETE, etc.
* request('apiUrl', options)
*/
// example
const sendRequsetMethod = async function(params) {
const res = await request('apiUrl', {
method: 'get' // or other method
headers: {}, // set request headers
params
})
return res;
}
const sendRequsetMethod = async function(params) {
const res = await request('apiUrl', {
method: 'post' // post or put
headers: {}, // set request headers
params, // body
payload // 设置为true则可以在url进行拼接参数
})
return res;
}