1.1.5 • Published 2 years ago

@foodism/http v1.1.5

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

ts版本http 请求库

安装

  npm install @foodism/http 

在项目中使用

import Service from "@foodism/http";

class Http extends Service {
  constructor(props?: any) {
  super();
  this.init();
}
init() {
  this.baseURL = "https://jsonplaceholder.typicode.com/";
  this.timeout = 1000;
  this.withCredentials = false;
  this.headers = {
    "Content-Type": "application/json",
  };
  super.setup();
}
}

const http = new Http();

interface Post {
  id: number;
  title: string;
}

async function getUsers() {
  // post 请求
  const data = await http.request<Post[]>({
    url: "/posts",
    method: "post",
    data: {
      userId: 10001,
      id: 100,
      title: "yagn-=titi",
      body: "body-yang",
    },
    headers: {
      "Content-Type": "application/json",
    },
  });
  // get 请求
  // 1. 把get请求的参数 拼接在url后面
  const data2 = await http.request({
    url: "/post?name=xx",
  });

  // 2. 把get请求的参数 放在data里面,自动拼接在url后面
  const data3 = await http.request({
    url: "/post",
    data: {
      name: "xx"
    }  
  });

  console.log("最终的值得");
  console.log(data);
}

getUsers();
1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.0

3 years ago

1.1.2

3 years ago

1.0.0

3 years ago

0.1.4

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago