Socket
Book a DemoInstallSign in
Socket

@dpapejs/axios-request

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dpapejs/axios-request

A request library based on Axios secondary encapsulation

latest
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

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

Keywords

dpapejs

FAQs

Package last updated on 31 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts