1.0.4 • Published 2 years ago

@dpapejs/axios-request v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

@dpapejs/axios-request

Description

A request library based on Axios secondary encapsulation

npm npm NPM

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" } });
1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago