@dpapejs/axios-request
v1.0.4
Published
A request library based on Axios secondary encapsulation
Downloads
2
Readme
@dpapejs/axios-request
Description
A request library based on Axios secondary encapsulation
Install
npm install @dpapejs/axios-request -S
Quick Start
import {
createRequest,
Get,
Post,
Put,
Del,
Form,
Download,
} from "@dpapejs/axios-request";
createRequest({
baseURL: "http://127.0.0.1:8080",
timeout: 30000,
headers: {
"Content-Type": "application/json",
},
setRequest(config) {
const token = Cookies.get("Authorization");
const result = {};
if (token) result.Authorization = `Bearer ${token}`;
return config;
},
requestFail(error) {
return Promise.reject(error);
},
success(response) {
const data = response.data || {};
const statusCode = data.code;
if (statusCode !== 200) {
return Promise.reject(result);
}
return data;
},
fail(error) {
return Promise.reject(error.response || {});
},
});
Get("/api/user/list", { data: { page: 1, pageSize: 10 } });
Post("/api/user/update", {
data: { username: "admin", password: "admin456", id: 5 },
});
Put("/api/user/add", { data: { username: "admin", password: "admin123" } });
Form("/api/user/photo", { data: { file: "file date" } });
Del("/api/user/delete/1");
Download("/api/download/execl", { data: { id: "xxxxxxx" } });
Download.post("/api/download/execl", { data: { id: "xxxxxxx" } });